I have GridView with CRUD operations, on load I'm adding one empty row with no data just to show the grid, after that I can add new rows, update, delete, but when I deleteall rowsmy grid disappears and I lose
Grid's header and footer.
.NET forums are moving to a new home on Microsoft Q&A, we encourage you to go to Microsoft Q&A for .NET for posting new questions and get involved today.
None
0 Points
5 Posts
How to show GridView's header and footer if all rows are deleted
Nov 21, 2020 10:41 PM|n3x|LINK
I have GridView with CRUD operations, on load I'm adding one empty row with no data just to show the grid, after that I can add new rows, update, delete, but when I delete all rows my grid disappears and I lose Grid's header and footer.
protected void Page_Load(object sender, EventArgs e) { GridView1.DataSource = new object[] { null }; GridView1.DataBind(); }
Is there any solution to set this row static?
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e) { if (e.Row.RowType == DataControlRowType.DataRow) { if (e.Row.DataItem == null) { e.Row.Visible = false; } } }
Contributor
3730 Points
1424 Posts
Re: How to show GridView's header and footer if all rows are deleted
Nov 23, 2020 06:14 AM|yij sun|LINK
Hi n3x,
Accroding to your description,I suggest you could set ShowFooter="true" , ShowHeader="true" and ShowHeaderWhenEmpty="true".
If you have other requirments,you could post sample to us.It will help us to solve your problems.
Just like this:
Code-behind:
Result:
Best regards,
Yijing Sun