Click here to Skip to main content
15,896,278 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i have to put checkbox in gridview for delete row.Delete rows where i have checked checkbox.
how to do this without using templatefield,iteamtemplate.
Is there any way to do this?
Posted
Comments
Richard C Bishop 24-Apr-13 11:42am    
No, there is not way to do this without using a templated field.

1 solution

Hi,

Take a look into the below code.

XML
<asp:GridView ID="gvmails" runat="server" AutoGenerateColumns="false">
           <Columns>
               <asp:TemplateField HeaderText="Select">
                   <ItemTemplate>
                       <asp:CheckBox ID="chkSelect" runat="server" />
                   </ItemTemplate>
               </asp:TemplateField>
               <asp:TemplateField HeaderText="Column 1">
                   <ItemTemplate>
                       <asp:Label ID="lblColumn1" runat="server" Text='<%# Eval("Column1") %>'></asp:Label>
                   </ItemTemplate>
               </asp:TemplateField>
               <asp:TemplateField HeaderText="Column 2">
                   <ItemTemplate>
                       <asp:Label ID="lblColumn2" runat="server" Text='<%# Eval("Column2") %>'></asp:Label>
                   </ItemTemplate>
               </asp:TemplateField>
           </Columns>
       </asp:GridView>


In OnSelectedIndexChanged event of checkbox write the code to delete a record. By using CommandArgument of checkbox you can get the record id to be deleted from gridview.

Hope this will solve your problem.

Regards,
Manoj
 
Share this answer
 

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