#
<%# Container.DataItemIndex+1 %>
1 have 7 rows in my grid . i want to hide 2,5 row from grid.after hiding two rows the grid the row number is like that 1,3,4,6,7
after hiding 2 rows row number is not correct
Deepak TewatiaPosted Dec 18, 2022, 4:16 PM
Hi lejo,
To hide rows in an ASP.NET GridView, you can use the Visible property of the GridViewRow object. You can access the row object using the Row property of the GridViewRowEventArgs object in the RowDataBound event of the GridView.
Based on your problem statement you can use the below code to hide rows 2 and 5 in a GridView:
Keep in mind that the RowIndex property of the GridViewRow object is zero-based, so the first row has an index of 0, the second row has an index of 1, and so on.
if you want fix the row numbers after hiding some rows, you can use the RowDataBound event to update the row numbers in the template field. Use the below code snippet to do this:
we are using a Label control with an ID of "lblRowNumber" in the template field to display the row number. You can adjust the code to fit your specific requirements.