aspdotnet-suresh offers articles and tutorials,csharp dot net, articles and tutorials,VB.NET Articles,Gridview articles,code examples of 2.0 /3.5,AJAX,SQL Server Articles,examples of .net technologies

Disable button if gridview doesn't contains any Data in

Sep 7, 2010

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 .

Happy Coding…

If you enjoyed this post, please support the blog below. It's FREE!

Get the latest,, VB.NET, jQuery, Plugins & Code Snippets for FREE by subscribing to our Facebook, Twitter, RSS feed, or by email.

subscribe by rss Subscribe by RSS subscribe by email Subscribe by Email


Anonymous said...

what is dataview can u please explain that..suresh bhaiyaa

Anonymous said...


Anonymous said...

search the records in gridview in using dataview

Give your Valuable Comments

Note: Only a member of this blog may post a comment.

© 2015 All Rights Reserved.
The content is copyrighted to Suresh Dasari and may not be reproduced on other websites without permission from the owner.