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 Asp.net, C#.net, VB.NET, jQuery, Plugins & Code Snippets for FREE by subscribing to our Facebook, Twitter, RSS feed, or by email. |
|||
|
|||
3 comments :
what is dataview can u please explain that..suresh bhaiyaa
ddddddddddddddddddddddddddddddddssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssss
search the records in gridview in asp.net using dataview
Note: Only a member of this blog may post a comment.