Here I will explain how to disable button if gridview doesn’t contain records.
Now I have a two button Button1 and Button2 and one gridview. Now I want to display Button2 and gridview whenever user click on Button1.if user clicks on Button1 before displaying the Button2 and gridview I need to check if gridview has data or not if that gridview doesn’t contain data disable Button2 and display gridview with No Records found .For that I have written one function in button click like this
private void CheckRecordCount(ObjectDataSource ods, Button btn)
DataView dv = new DataView();
dv = (DataView)ods.Select();
if (dv != null)
SetImageButtons(dv.Table.Rows.Count == 0 ? false : true);
/// To enable/disable the buttonprivate void SetImageButtons(bool isEnabled)
if (isEnabled == false)
btn.Enabled = isEnabled;
By achiving this functionality call the CheckRecordCount function in Button1 click with two parameters .