private void BindGrid(string searchTerm = "") { var data = GetData(); int totalEntries = data.Count; if (!string.IsNullOrWhiteSpace(searchTerm)) { data = data.Where(d => d.GetType().GetProperties() .Any(prop => prop.GetValue(d, null)?.ToString().IndexOf(searchTerm, StringComparison.OrdinalIgnoreCase) >= 0)).ToList(); } int filteredEntries = data.Count; int entriesPerPage = GridView1.PageSize; GridView1.AllowPaging = true; // Adjust PageIndex if it exceeds the number of available pages int totalPages = (int)Math.Ceiling((double)filteredEntries / entriesPerPage); if (GridView1.PageIndex >= totalPages) { GridView1.PageIndex = totalPages - 1; // Set to last page if current exceeds total } // Ensure PageIndex is reset if no results are found if (filteredEntries == 0) { GridView1.PageIndex = 0; } GridView1.DataSource = data.Skip(GridView1.PageIndex * entriesPerPage).Take(entriesPerPage).ToList(); GridView1.DataBind(); LabelEntryCount.Text = $"Showing {GridView1.Rows.Count} of {filteredEntries} entries"; GridView1.Visible = filteredEntries > 0; GridView1.PagerSettings.Visible = filteredEntries > entriesPerPage; }
private void BindGrid() { var data = GetData(); int totalEntries = data.Count; GridView1.DataSource = GetData(); GridView1.DataBind(); int currentPageEntries = GridView1.Rows.Count; LabelEntryCount.Text = "Showing " + currentPageEntries + " of " + totalEntries + " entries"; }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)