Hide Gridview when the data is not present
10,791
Solution 1
protected void GridView1_DataBound(object sender, EventArgs e)
{
if (this.GridView1.Rows.Count == 0)
this.GridView1.Visible = false;
}
Solution 2
<asp:Gridview id="gridview" ......
Visible='<%# ((ICollection)gridview.DataSource).Count == 0 ? false : true %>'>
Author by
John Smith
Full Stack Developer => Angular 2+, Angularjs, C#, SQL, Jquery, Javascript
Updated on June 04, 2022Comments
-
John Smith almost 2 years
I have a Gridview that has filters that can fire off the emptydata template. However when this is displayed I can still see the outline of my gridview. How can I make the Gridview disappear when the data is not present?
-
John Smith over 14 yearssounds great...but how can i do that in code and where? Gridview databound? how can i get access to the emptydata template in code?
-
jscharf over 14 yearsGridView is an ASP.NET control, which means it will have a 'Visible' property, allowing you to show or hide the control itself. GridView.Visible = false; will prevent the control from being rendered at all.
-
John Smith over 14 yearsWhat i wanted was for the Gridview borders to be hidden. Databoud was the correct place to do it. Thank you