Click here to Skip to main content
15,885,985 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I want to set multiple check box and check box header in gridview with asp.net with c#. I am using xdatagrid for the same. I need to verify all details on selecting multiple checkbox values or the checkbox header for all entries in the grid.

What I have tried:

<cc1:XDataGrid ID="grdIPI" runat="server" Width="100%"
                                            AutoGenerateColumns="False" AllowPaging="true" AllowCustomPaging="True"
                                            CssClass="NeST_DATAGRID_FIXED_SIZE" ShowFooter="True" OnItemCommand="grdIPI_ItemCommand"
                                            OnPageIndexChanged="grdIPI_PageIndexChanged" OnPagerClicked="grdIPI_PagerClicked" PageSize="10" OnItemDataBound="grdIPI_ItemDataBound">
                                            <AlternatingItemStyle BorderWidth="0px" CssClass="NeST_DATAGRID_CELLDATA2"></AlternatingItemStyle>
                                            <ItemStyle BorderWidth="0px" CssClass="NeST_DATAGRID_CELLDATA" HorizontalAlign="Left"></ItemStyle>
                                            <HeaderStyle CssClass="NeST_DATAGRID_HEADING"></HeaderStyle>
                                            <PagerStyle HorizontalAlign="Right" Mode="NumericPages" Wrap="True" CssClass="DATAGRID_NEW_CELLDATA" />
                                            <Columns>
                                                <asp:TemplateColumn HeaderText="Sl.No">
                                                    <ItemTemplate>
                                                        <%--<asp:Label ID="O_SlNo" runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.SlNo") %>'> </asp:Label>--%>
                                                        <asp:LinkButton ID="lnkTitle" runat="server"  Text='<%# DataBinder.Eval(Container, "DataItem.SlNo") %>' CommandName="NextAction"></asp:LinkButton>
                                                        <input id="hidEnable" runat="server" name="hidEnable" type="hidden" value='<%# DataBinder.Eval(Container, "DataItem.StatusID") %>' />

                                                    </ItemTemplate>
                                                    <HeaderStyle Width="5%" />
                                                </asp:TemplateColumn>

                                                <asp:TemplateColumn HeaderText="Ordering Customer Name">
                                                    <ItemTemplate>
                                                        <asp:Label ID="O_OrderingCustomerNamee" runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.OrderingCustomerName") %>'>
                                                        </asp:Label>
                                                    </ItemTemplate>
                                                    <HeaderStyle Width="13%" />
                                                </asp:TemplateColumn>

                                                 <asp:TemplateColumn HeaderText="Ordering Customer Account">
                                                    <ItemTemplate>
                                                        <asp:Label ID="O_OrderingCustomerAccount" runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.OrderingCustomerAccount") %>'>
                                                        </asp:Label>
                                                    </ItemTemplate>
                                                    <HeaderStyle Width="13%" />
                                                </asp:TemplateColumn>




                                                <asp:TemplateColumn HeaderText="Beneficiary Customer Name" ItemStyle-HorizontalAlign="Center">
                                                    <ItemTemplate>
                                                        <asp:Label ID="O_BeneficiaryAccountName" runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.BeneficiaryAccountName") %>'>
                                                        </asp:Label>
                                                    </ItemTemplate>
                                                    <HeaderStyle Width="14%" />

                                                    <ItemStyle HorizontalAlign="Center"></ItemStyle>
                                                </asp:TemplateColumn>


                                                <asp:TemplateColumn HeaderText="Beneficiary Account">
                                                    <ItemTemplate>
                                                        <asp:Label ID="O_BeneficiaryAccount" runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.BeneficiaryAccount") %>'>
                                                        </asp:Label>
                                                    </ItemTemplate>
                                                    <HeaderStyle Width="10%" />

                                                    <ItemStyle HorizontalAlign="Center"></ItemStyle>
                                                </asp:TemplateColumn>

                                                <asp:TemplateColumn HeaderText="Total Amount" ItemStyle-HorizontalAlign="Center">
                                                    <ItemTemplate>
                                                        <asp:Label ID="O_instructedAmount" runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.instructedAmount") %>'>
                                                        </asp:Label>
                                                        <input type="hidden" runat="server" id="hidOUT_IPIID" name="Id" value='<%# DataBinder.Eval(Container, "DataItem.WSI_OUT_IPIID") %>' />
                                                    </ItemTemplate>
                                                    <HeaderStyle Width="8%" />

                                                    <ItemStyle HorizontalAlign="Right"></ItemStyle>
                                                </asp:TemplateColumn>




                                                <asp:TemplateColumn HeaderText="Purpose" ItemStyle-HorizontalAlign="Center">
                                                    <ItemTemplate>
                                                        <asp:Label ID="O_pop" runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.PURPOSE") %>'>
                                                        </asp:Label>

                                                    </ItemTemplate>
                                                    <HeaderStyle Width="9%" />

                                                    <ItemStyle HorizontalAlign="center"></ItemStyle>
                                                </asp:TemplateColumn>


                                                  <asp:TemplateColumn HeaderText="Remittance info" ItemStyle-HorizontalAlign="Center">
                                                    <ItemTemplate>
                                                        <asp:Label ID="O_Remitanceinfo" runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.RemittanceInfo") %>'>
                                                        </asp:Label>

                                                    </ItemTemplate>
                                                    <HeaderStyle Width="9%" />

                                                    <ItemStyle HorizontalAlign="center"></ItemStyle>
                                                </asp:TemplateColumn>

                                                <asp:TemplateColumn HeaderText="Senders Ref" ItemStyle-HorizontalAlign="Center">
                                                    <ItemTemplate>
                                                        <asp:Label ID="O_SenedersRef" runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.sendersRef") %>'>
                                                        </asp:Label>

                                                    </ItemTemplate>
                                                    <HeaderStyle Width="7%" />

                                                    <ItemStyle HorizontalAlign="center"></ItemStyle>
                                                </asp:TemplateColumn>

                                               <asp:TemplateColumn HeaderText="Current Status">
                                                    <ItemTemplate>
                                                        <asp:Label ID="CurrentStatus" runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.CurrentStatusId") %>'>
                                                        </asp:Label>
                                                    </ItemTemplate>
                                                    <HeaderStyle Width="12%" />
                                                    <ItemStyle HorizontalAlign="left"></ItemStyle>
                                                </asp:TemplateColumn>
                                                <%--<asp:ButtonColumn DataTextField="CurrentStatusId" HeaderText="Current Status" CommandName="NextAction">
                                                    <HeaderStyle Width="20%" />
                                                </asp:ButtonColumn>--%>

                                            </Columns>
                                            <%-- <PagerStyle CssClass="C3_DATAGRID_CELLDATANEW" HorizontalAlign="Right" Mode="NumericPages"
                                                        Wrap="True" />--%>
                                        </cc1:XDataGrid>
Posted
Updated 9-Oct-18 8:39am

1 solution

I don't know how xDataGrid was built, but if that control was derived from standard GridView, then you could setup a HeaderTemplate inside your TemplateColumn and add your CheckBox there. For more information,see: TemplateField.HeaderTemplate Property (System.Web.UI.WebControls) | Microsoft Docs[^]

Here's an example on how to use CheckBox and preserve the state on paging: https://www.aspsnippets.com/Articles/Preserving-state-of-Checkboxes-while-paging-in-ASP.Net-GridView-Control.aspx[^]
 
Share this answer
 
v2
Comments
ranio 9-Oct-18 23:50pm    
what i need is to select all checkbox on clicking checkbox header and update. Also i need to maintain the checkbox checked while navigating to another page with in the grid.
Vincent Maverick Durano 10-Oct-18 10:25am    
I've updated the solution and added a link for a tutorial. Read it and understand how it works. The idea behind it is to store the state in a Session or Viewstate so you can reference the selected CheckBox on switching pages.
Maciej Los 10-Oct-18 11:20am    
5ed!
Vincent Maverick Durano 10-Oct-18 11:27am    
Thank you Maciej! :)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900