I have asp.net gridview with 5 textboxes in every row. Page size of gridview is 20 records on each page. I have enabled sorting on every column. When gridview is getting populated, then we are getting 28 filled records and 12 empty records.
When I hit sorting in asc mode on any column, It gives blank rows earlier then records are coming. I wanted to ignore those blank records while sorting.
I tried using custom onsorting method on gridview but its not working.

Tahir AnsariRank #366 · 6.8K reputationPosted Aug 11, 2023, 10:15 AM EDT
protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { BindGridView(); } } private void BindGridView() { // Assume you have a method to retrieve your data source DataTable dataSource = GetDataSource(); // Filter out blank rows from the data source DataView filteredView = new DataView(dataSource); filteredView.RowFilter = "Column1 IS NOT NULL AND Column2 IS NOT NULL AND Column3 IS NOT NULL"; // Add conditions for each column // Bind the filtered data to the GridView GridView1.DataSource = filteredView; GridView1.DataBind(); } protected void GridView1_Sorting(object sender, GridViewSortEventArgs e) { // Implement your custom sorting logic here // Make sure to use the filtered data source for sorting BindGridView(); }Cr BhargaviRank #420 · 5.9K reputationPosted Aug 13, 2023, 4:02 AM EDT
You can take to troubleshoot and potentially resolve the issue:
Data Source Handling: Ensure that you're binding the GridView to a proper data source that does not include the empty records. Check the data source query or collection that you're using to populate the GridView.
Filtering Empty Records: Before binding the data to the GridView, make sure to filter out the empty records from the dataset. You can use LINQ or other methods to remove rows with empty values from the data source.
Debugging: Place breakpoints and debug statements in your data binding, sorting, and paging code to see the flow of data and events. This can help you pinpoint where the issue is occurring and what might be causing it.