I want to maintain the checkbox state with in a gridview while using ajax tab container in asp.net with c#. I have checked a checkbox with in the grid but checked state is coming as false.
I am using the activetabindex changed event with Auto post true of the ajax tab container but check box state in the grid even if checked coming as unchecked.
<asp:TabContainer ID="tabContainer" runat="server" ActiveTabIndex="0" onactivetabchanged="tabContainer_ActiveTabChanged">
<asp:TabPanel ID="tpnlPresentment" runat="server" HeaderText="Presentment" TabIndex="1">
<ContentTemplate><pre> <cc1:XDataGrid ID="grdDDEnvelope" runat="server" AllowPaging="True" AllowCustomPaging="True"
Width="100%" AutoGenerateColumns="False" CssClass="NeST_DATAGRID_FIXED_SIZE"
ShowFooter="True" OnPageIndexChanged="grdDDEnvelope_PageIndexChanged" OnItemDataBound="grdDDEnvelope_ItemDataBound"
OnPagerClicked="grdDDEnvelope_PagerClicked" OnItemCommand="grdDDEnvelope_ItemCommand"
OnSortCommand="grdDDEnvelope_OnSortCommand" AllowSorting="True" PageSize="3">
<AlternatingItemStyle BorderWidth="0px" CssClass="NeST_DATAGRID_CELLDATA2" Wrap="True">
</AlternatingItemStyle>
<Columns>
<asp:TemplateColumn HeaderText="Sl.No">
<ItemTemplate>
<asp:Label runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.SlNo") %>'
ID="Id" /><br />
<input type="hidden" runat="server" id="hidDetailId" name="hidDetailId" value='<%# DataBinder.Eval(Container, "DataItem.OUT_500_FileDetailID") %>' /><asp:ImageButton
ID="imgPDF" ToolTip="Click to View Report" CommandName="View" Width="30px" ImageUrl="~/Images/PDF.jpg"
runat="server" Visible="false" /></ItemTemplate>
<HeaderStyle Width="2%"></HeaderStyle>
<ItemStyle HorizontalAlign="Center" />
</asp:TemplateColumn>
<asp:TemplateColumn HeaderText="Installment Date" HeaderStyle-ForeColor="White" SortExpression="PaymentDate">
<ItemTemplate>
<asp:Label runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.PaymentDate","{0:dd-MMM-yyyy}") %>'
ID="PDate" /></ItemTemplate>
<HeaderStyle HorizontalAlign="Center" Width="5%"></HeaderStyle>
<ItemStyle HorizontalAlign="Center" />
</asp:TemplateColumn>
<asp:TemplateColumn HeaderText="Created Date">
<ItemTemplate>
<asp:Label runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.CreatedDate","{0:dd-MMM-yyyy HH:mm:ss}") %>'
ID="PcreatedDate" /></ItemTemplate>
<HeaderStyle HorizontalAlign="Center" Width="5%"></HeaderStyle>
<ItemStyle HorizontalAlign="Center" />
</asp:TemplateColumn>
<asp:TemplateColumn HeaderText="Payer Identification Number" HeaderStyle-ForeColor="White"
SortExpression="ISNumber">
<ItemTemplate>
<asp:Label runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.ISNumber") %>'
ID="ISNo" /></ItemTemplate>
<HeaderStyle HorizontalAlign="Center" Width="5%"></HeaderStyle>
<ItemStyle HorizontalAlign="Center" />
</asp:TemplateColumn>
<asp:TemplateColumn HeaderText="Type">
<ItemTemplate>
<asp:Label runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.OperationType") %>'
ID="ISType" /></ItemTemplate>
<HeaderStyle HorizontalAlign="Center" Width="5%"></HeaderStyle>
<ItemStyle HorizontalAlign="Center" />
</asp:TemplateColumn>
<asp:TemplateColumn HeaderText="Claimed Amount" HeaderStyle-ForeColor="White" SortExpression="ClaimedAmount">
<ItemTemplate>
<asp:Label runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.ClaimedAmount","{0:###,####,###.00}") %>'
ID="TotalAmount" /></ItemTemplate>
<HeaderStyle HorizontalAlign="Center" Width="5%"></HeaderStyle>
<ItemStyle HorizontalAlign="Right" />
</asp:TemplateColumn>
<asp:TemplateColumn HeaderText="Payer IBAN" HeaderStyle-ForeColor="White" SortExpression="Payer">
<ItemTemplate>
<asp:TextBox ID="Payer" runat="server" Style="position: static" CssClass="NeST_GRIDMTEXTBOX"
Width="95%" ReadOnly="true" TextMode="MultiLine" Text='<%# DataBinder.Eval(Container, "DataItem.Payer") %>' /></ItemTemplate>
<HeaderStyle HorizontalAlign="Center" Width="10%"></HeaderStyle>
</asp:TemplateColumn>
<asp:TemplateColumn HeaderText="DDA Reference No" HeaderStyle-ForeColor="White" SortExpression="MandateReference">
<ItemTemplate>
<asp:TextBox ID="DDAReferenceNumber" runat="server" Style="position: static" CssClass="NeST_GRIDMTEXTBOX"
Width="98%" ReadOnly="true" TextMode="MultiLine" Text='<%# DataBinder.Eval(Container, "DataItem.MandateReference") %>' /></ItemTemplate>
<HeaderStyle HorizontalAlign="Center" Width="10%"></HeaderStyle>
</asp:TemplateColumn>
<asp:TemplateColumn HeaderText="Select">
<ItemTemplate>
<asp:CheckBox ID="chkEnvelopeSelect" onclick="javascript:CheckUncheck('ctl00_cphDDS_tabContainer_tpnlPresentment_grdDDEnvelope',this);"
runat="server"></asp:CheckBox></ItemTemplate>
<HeaderTemplate>
Select
<br />
<asp:CheckBox ID="chkallSelect" runat="server" onclick="javascript:DGSelectOrUnselectAll('ctl00_cphDDS_tabContainer_tpnlPresentment_grdDDEnvelope',this,'chkEnvelopeSelect');"
Enabled="true" /></HeaderTemplate>
<HeaderStyle Width="2%"></HeaderStyle>
<ItemStyle HorizontalAlign="Center" />
</asp:TemplateColumn>
<asp:TemplateColumn HeaderText="Payer Name">
<ItemTemplate>
<asp:TextBox ID="PayerName" runat="server" Style="position: static" CssClass="NeST_GRIDMTEXTBOX"
Width="95%" ReadOnly="true" TextMode="MultiLine" Text='<%# DataBinder.Eval(Container, "DataItem.PayerName") %>' /></ItemTemplate>
<HeaderStyle HorizontalAlign="Center" Width="8%"></HeaderStyle>
</asp:TemplateColumn>
<asp:TemplateColumn HeaderText="Remarks">
<ItemTemplate>
<asp:TextBox ID="TxtReason" runat="server" Width="95%" TextMode="MultiLine" CssClass="NeST_MTEXTBOX"
MaxLength="1000" Style="position: static" /></ItemTemplate>
<HeaderStyle Width="5%" />
</asp:TemplateColumn>
<asp:TemplateColumn HeaderText="Paying Bank">
<ItemTemplate>
<asp:TextBox ID="PayingBank" runat="server" Style="position: static" CssClass="NeST_GRIDMTEXTBOX"
Width="95%" ReadOnly="true" TextMode="MultiLine" Text='<%# DataBinder.Eval(Container, "DataItem.PayingBank") %>' /></ItemTemplate>
<HeaderStyle HorizontalAlign="Center" Width="7%"></HeaderStyle>
</asp:TemplateColumn>
<asp:TemplateColumn HeaderText="Originator Account No">
<ItemTemplate>
<asp:TextBox ID="OriginatorAccountNumber" runat="server" Style="position: static"
CssClass="NeST_GRIDMTEXTBOX" Width="94%" ReadOnly="true" TextMode="MultiLine"
Text='<%# DataBinder.Eval(Container, "DataItem.OriginatorAccountNumber") %>' /></ItemTemplate>
<HeaderStyle HorizontalAlign="Center" Width="9%"></HeaderStyle>
</asp:TemplateColumn>
<asp:TemplateColumn HeaderText="Final Beneficiary">
<ItemTemplate>
<asp:TextBox ID="FinalBenificaryAccountNo" runat="server" Style="position: static"
CssClass="NeST_GRIDMTEXTBOX" Width="94%" ReadOnly="true" TextMode="MultiLine"
Text='<%# DataBinder.Eval(Container, "DataItem.FinalBenificaryAccountNo") %>' /></ItemTemplate>
<HeaderStyle HorizontalAlign="Center" Width="9%"></HeaderStyle>
</asp:TemplateColumn>
<asp:TemplateColumn HeaderText="NAK/CB Error">
<ItemTemplate>
<asp:TextBox ID="TxtNAkError" runat="server" Style="position: static" CssClass="NeST_GRIDMTEXTBOX"
Width="94%" ReadOnly="true" TextMode="MultiLine" Text='<%# DataBinder.Eval(Container, "DataItem.NAkErrorDescription") %>' /></ItemTemplate>
<HeaderStyle Width="5%"></HeaderStyle>
<ItemStyle HorizontalAlign="Justify" />
</asp:TemplateColumn>
<asp:TemplateColumn HeaderText="Current Status">
<ItemTemplate>
<asp:TextBox ID="StatusName" runat="server" Style="position: static" CssClass="NeST_GRIDMTEXTBOX"
Width="95%" ReadOnly="true" TextMode="MultiLine" Text='<%# DataBinder.Eval(Container, "DataItem.StatusName") %>' /></ItemTemplate>
<HeaderStyle Width="6%"></HeaderStyle>
<ItemStyle HorizontalAlign="Justify" />
</asp:TemplateColumn>
</Columns>
<HeaderStyle CssClass="NeST_DATAGRID_HEADING" HorizontalAlign="Center"></HeaderStyle>
<ItemStyle Height="40px" BorderWidth="0px" CssClass="NeST_DATAGRID_CELLDATA" HorizontalAlign="Left">
</ItemStyle>
<PagerStyle HorizontalAlign="Left" CssClass="NeST_DATAGRID_CELLDATANEW" Mode="NumericPages"
Wrap="True"></PagerStyle>
</cc1:XDataGrid>
What I have tried:
In the active tab index changed even on checking the checkbox in the grid checkbox state coming as false.
List<OUT_500_DETAIL> ListDashboard = new List<OUT_500_DETAIL>();
if ((List<OUT_500_DETAIL>)ViewState["RepEnvelopeGrid"] != null)
{
ListDashboard = (List<OUT_500_DETAIL>)ViewState["RepEnvelopeGrid"];
}
OUT_500_DETAIL objDashboard;
int index = -1;
for (int i = 0; i < grdRepresentment.Items.Count; i++)
{
objDashboard = new OUT_500_DETAIL();
objDashboard.OUT_500_FileDetailID = Convert.ToDecimal(((HtmlInputHidden)grdRepresentment.Items[i].FindControl("hidDetailId")).Value);
objDashboard.RemarksByBC = ((TextBox)grdRepresentment.Items[i].FindControl("TxtReason")).Text.ToString();
CheckBox chkEnvelopeSelect = (CheckBox)grdRepresentment.Items[i].FindControl("chkRepEnvelopeSelect");
if (chkEnvelopeSelect != null)
{
try
{
index = ListDashboard.Select((item, k) => new { Item = item, Index = k }).First(x => x.Item.OUT_500_FileDetailID == objDashboard.OUT_500_FileDetailID).Index;
}
catch
{
}
if (index != -1)
{
ListDashboard.RemoveAt(index);
}
if (chkEnvelopeSelect.Checked)
{
ListDashboard.Add(objDashboard);
}
index = -1;
}
}
ViewState["RepEnvelopeGrid"] = ListDashboard;