I have a Grid View, I want to update all the rows that will be selected by checking the checkbook. First I want all the selected rows into a list. I don know how to do it. I know how to populate a grid from a list.
my grid view is
<asp:GridView runat="server" ID="GridForResult"
Visible="true"
ShowHeader="false"
AutoGenerateColumns="false">
<Columns>
<asp:TemplateField ItemStyle-Width="120px" ItemStyle-Height="22px">
<ItemTemplate>
<%#Eval( "TestRoll")%>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField ItemStyle-Width="150px" ItemStyle-Height="22px">
<ItemTemplate>
<%#Eval( "Name")%>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField ItemStyle-Width="80px" ItemStyle-Height="22px">
<ItemTemplate>
<%#Eval( "Program")%>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField ItemStyle-Width="80px" ItemStyle-Height="22px">
<ItemTemplate>
<asp:CheckBox ID="chkSelected" runat="server" Text="Selected" />
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
My another problem is How to get only the selected (checkboxes) rows from the gridview?
Its pretty straight forward if you are not paging your grid and you want to maintain checked value on PostBack.
On GridView Markup, set
DataKeyNames="{your primary key}"Code – behind
The
List<string>primaryKeys will now hold all the checked primary keys.