<asp:GridView ID="gvAppvrDetail" runat="server" AutoGenerateColumns="False" AllowPaging="true" PageSize="10" Width="1000PX" onpageindexchanging="gvAppvrDetail_PageIndexChanging" onrowdatabound="gvAppvrDetail_RowDataBound" > <Columns> <asp:TemplateField> <HeaderTemplate> <asp:CheckBox ID="ChkAll" runat="server" onclick="javascript:SelectAllCheckboxes(this);" > </asp:CheckBox> </HeaderTemplate> <ItemTemplate> <asp:CheckBox ID="ChkChild" runat="server" onclick="CheckBoxCount();" OnCheckedChanged="ChkChild_CheckedChanged" > </asp:CheckBox> </ItemTemplate> </asp:TemplateField>
</Columns>
</asp:GridView>
gvAppvrDetail_PageIndexChanging
protected void gvAppvrDetail_PageIndexChanging(object sender, GridViewPageEventArgs e) { gvAppvrDetail.PageIndex = e.NewPageIndex; BindGridview(Request.QueryString["PREFIX"].ToString()); //Code to maintain selected record while paging if (ViewState["SelectedRows"] != null) { List<string> selectedItems = (List<string>)ViewState["SelectedRows"]; foreach (GridViewRow row in gvAppvrDetail.Rows) { Label lblEntryNo = (Label)row.FindControl("lblEntryNo"); var result = selectedItems.Find(item => item == lblEntryNo.Text); if (result != null) { CheckBox chk = (CheckBox)row.FindControl("ChkChild"); if (chk != null) { chk.Checked = true; ViewState["Count"] = Convert.ToInt32(ViewState["Count"]) + 1; lblcntRows.Text = ViewState["Count"].ToString(); } } } } //BindGridview(Request.QueryString["PREFIX"].ToString()); }
ChkChild_CheckedChanged
protected void ChkChild_CheckedChanged(object sender, EventArgs e) { CheckBox chkStatus = (CheckBox)sender; GridViewRow selectedrow = (GridViewRow)chkStatus.NamingContainer; //Getting selected records from View state List<string> selectedItems = null; if (ViewState["SelectedRows"] != null) { selectedItems = (List<string>)ViewState["SelectedRows"]; } else { selectedItems = new List<string>(); } Label lblEntryNo = (Label)selectedrow.FindControl("lblEntryNo"); if (chkStatus.Checked) { selectedItems.Add(lblEntryNo.Text); } else { var result = selectedItems.Find(item => item == lblEntryNo.Text); if (result != null) { selectedItems.Remove(lblEntryNo.Text); } } //Assigning Selected records to ViewState ViewState["SelectedRows"] = selectedItems; }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)