asp.net - add Delete button at last column in gridview -
i adding columns on grid-view dynamically
datatable dt1 = new datatable(); dt1.columns.add("item title", typeof(string)); dt1.columns.add("unit pack", typeof(string)); dt1.columns.add("pack", typeof(string)); gv1.datasource = dt1; gv1.databind();
and add delete button automatically
by
<asp:gridview id="gv" runat="server"> <columns> <asp:commandfield showdeletebutton="true" /> </columns> </asp:gridview>
it shows gridview
| delete | item title | unit pack | pack |
now want show delete button @ last column like
| item title | unit pack | pack | delete |
how can this? how create delete button @ last column?
you adding column dynamically thats why need add delete column dynamic. or can add linkbutton in rowdatabound:
protected void gv_rowdatabound(object sender, gridviewroweventargs e) { if (e.row.dataitem != null) { linkbutton lb = new linkbutton(); lb.commandargument = e.row.cells[3].text; lb.commandname = "delete"; lb.text = "delete"; e.row.cells[3].controls.add((control)lb); } }
in rowcommand can write code delete:
protected void gv_rowcommand(object sender, commandeventargs e) { switch (e.commandname.tolower()) { case "delete": //your code here break; default: break; } }
Comments
Post a Comment