asp.net - Delete Link Button not working in GridView using ASP -


so there's not explain, have gridview , put delete button asks if you're sure want delete when click it. i'm using visualstudio2012 , i've done in many other pages i've never gotten problem.

gridview:

<asp:gridview id="maintenancetable" runat="server" allowpaging="true" allowsorting="true" autogeneratecolumns="false" datakeynames="maintenance_id" datasourceid="maintdatasource" emptydatatext="there no data records display." backcolor="white" bordercolor="#999999" borderstyle="none" borderwidth="1px" cellpadding="3" gridlines="vertical" width="1000px">     <alternatingrowstyle backcolor="#dcdcdc" />     <columns>         <asp:templatefield>             <itemtemplate>                 <asp:linkbutton runat="server" id="deletebutton" text="delete"                     commandname="delete"                     onclientclick="if (!window.confirm('are sure want delete item?')) return false;" />             </itemtemplate>         </asp:templatefield>         <asp:commandfield showeditbutton="true" showselectbutton="true" />         <asp:boundfield datafield="maintenance_id" headertext="maintenance_id" insertvisible="false" readonly="true" sortexpression="maintenance_id" />         <asp:checkboxfield datafield="status" headertext="status" sortexpression="status" />         <asp:boundfield datafield="date" headertext="date" sortexpression="date" />         <asp:boundfield datafield="notes" headertext="notes" sortexpression="notes" />     </columns>     <editrowstyle backcolor="#999999" />     <footerstyle backcolor="#cccccc" forecolor="black" />     <headerstyle backcolor="#34397d" font-bold="true" forecolor="white" />     <pagerstyle backcolor="#999999" forecolor="black" horizontalalign="center" />     <rowstyle backcolor="#eeeeee" forecolor="black" />     <selectedrowstyle backcolor="#008a8c" font-bold="true" forecolor="white" />     <sortedascendingcellstyle backcolor="#f1f1f1" />     <sortedascendingheaderstyle backcolor="#0000a9" />     <sorteddescendingcellstyle backcolor="#cac9c9" />     <sorteddescendingheaderstyle backcolor="#000065" /> </asp:gridview> 

this code i've added in terms of deleting in gridview:

<asp:templatefield>             <itemtemplate>                 <asp:linkbutton runat="server" id="deletebutton" text="delete"                     commandname="delete"                     onclientclick="if (!window.confirm('are sure want delete item?')) return false;" />             </itemtemplate>         </asp:templatefield> 

you need add following code:

protected void maintenancetable_rowcommand(object sender,                       gridviewcommandeventargs e) {   if (e.commandname == "delete")   {     // maintenanceid of clicked row     int maintenanceid = convert.toint32(e.commandargument);     // delete record      deleterecordbyid(maintenanceid);     // implement    } } 

just incase, make sure use "delete" not "delete".

check resource gridview delete, confirmation


Comments

Popular posts from this blog

cakephp - simple blog with croogo -

How to group boxplot outliers in gnuplot -

bash - Performing variable substitution in a string -