which is to add a checkbox feature so that a single checkbox can select multiple rows with same values.
<asp:GridView ID="GridViewRemittance" runat="server" AllowPaging="True" AutoGenerateColumns="False" AutoGenerateRows="False" OnRowDataBound="GridViewRemittance_RowDataBound" BorderColor="#3366CC" BorderStyle="None" BorderWidth="1px" Font-Names="Verdana" EmptyDataText="NO DATA FOUND" OnPageIndexChanging="GridViewRemittance_PageIndexChanging" OnRowCancelingEdit="GridViewRemittance_RowCancelingEdit" OnRowEditing="GridViewRemittance_RowEditing" OnRowUpdating="GridViewRemittance_RowUpdating" PageSize="300" Width="50%" BackColor="White" CellPadding="4">
<FooterStyle BorderColor="#CCCCCC" BorderStyle="Solid" BorderWidth="1px" BackColor="#99CCCC" ForeColor="#003399" />
<PagerStyle BorderColor="#CCCCCC" BorderStyle="Solid" BorderWidth="1px" BackColor="#99CCCC" ForeColor="#003399" HorizontalAlign="Left" />
<HeaderStyle BackColor="#006699" BorderColor="#CCCCCC" BorderStyle="Solid" BorderWidth="1px" Font-Size="15px" Height="30px" Font-Bold="True" ForeColor="White" />
<RowStyle BorderColor="#990000" BorderStyle="Solid" BorderWidth="1px" Font-Size="13px" Height="20px" ForeColor="#000066" />
<AlternatingRowStyle BorderColor="#990000" ForeColor="#000066" BackColor="#ffcc99" />
<Columns>
<asp:TemplateField HeaderText="Select">
<ItemTemplate>
<asp:CheckBox ID="SelectCheckBox" Width="50px" runat="server" AutoPostBack="true" OnCheckedChanged="SelectCheckBox_OnCheckedChanged" ></asp:CheckBox>
</ItemTemplate>
</asp:TemplateField>
I need to add a checkbox feature in the code above so that a single checkbox can select multiple rows with the same values.
To add a checkbox feature so that a single checkbox can select multiple rows with the same values, you can modify the code as follows:
<asp:GridView ID="GridViewRemittance" runat="server" AllowPaging="True" AutoGenerateColumns="False" AutoGenerateRows="False" OnRowDataBound="GridViewRemittance_RowDataBound" BorderColor="#3366CC" BorderStyle="None" BorderWidth="1px" Font-Names="Verdana" EmptyDataText="NO DATA FOUND" OnPageIndexChanging="GridViewRemittance_PageIndexChanging" OnRowCancelingEdit="GridViewRemittance_RowCancelingEdit" OnRowEditing="GridViewRemittance_RowEditing" OnRowUpdating="GridViewRemittance_RowUpdating" PageSize="300" Width="50%" BackColor="White" CellPadding="4">
<FooterStyle BorderColor="#CCCCCC" BorderStyle="Solid" BorderWidth="1px" BackColor="#99CCCC" ForeColor="#003399" />
<PagerStyle BorderColor="#CCCCCC" BorderStyle="Solid" BorderWidth="1px" BackColor="#99CCCC" ForeColor="#003399" HorizontalAlign="Left" />
<HeaderStyle BackColor="#006699" BorderColor="#CCCCCC" BorderStyle="Solid" BorderWidth="1px" Font-Size="15px" Height="30px" Font-Bold="True" ForeColor="White" />
<RowStyle BorderColor="#990000" BorderStyle="Solid" BorderWidth="1px" Font-Size="13px" Height="20px" ForeColor="#000066" />
<AlternatingRowStyle BorderColor="#990000" ForeColor="#000066" BackColor="#ffcc99" />
<Columns>
<asp:TemplateField HeaderText="Select">
<ItemTemplate>
<asp:CheckBox ID="SelectCheckBox" Width="50px" runat="server" AutoPostBack="true" OnCheckedChanged="SelectCheckBox_OnCheckedChanged" ></asp:CheckBox>
</ItemTemplate>
<HeaderTemplate>
<asp:CheckBox ID="SelectAllCheckBox" runat="server" AutoPostBack="true" OnCheckedChanged="SelectAllCheckBox_OnCheckedChanged" ></asp:CheckBox>
</HeaderTemplate>
</asp:TemplateField>
Here, I added a HeaderTemplate
within the TemplateField
for the checkbox in the header row. This checkbox will act as a “Select All” checkbox. You should also add the necessary logic in the code-behind file to handle the events SelectCheckBox_OnCheckedChanged
and SelectAllCheckBox_OnCheckedChanged
for selecting multiple rows with the same values.