javascript - calling OnRowDeleting Method using asp:TemplateField or asp:CommandField -
i trying show confirm message user on pressing delete button of every row. tried using <asp:commandfield showdeletebutton="true" buttontype="button" /> problem can not show confirmation message.
then tried using asp:templatefield button. problem asp:templatefield can not call onrowdeleting method confirmation message. code behind method on pressing delete button not executed, onrowdeleting="gridview1_rowdeleting". why so?
asp code::
<asp:gridview id="gridview1" runat="server" font-size="11px" autogeneratecolumns="false" width="90%" cssclass="gridview" alternatingrowstyle-cssclass="even" datakeynames="id" onrowdeleting="gridview1_rowdeleting" headerstyle-horizontalalign="left"> <columns> <asp:templatefield headertext = "s no."> <itemtemplate> <%#container.dataitemindex+1 %> </itemtemplate> </asp:templatefield> <asp:boundfield datafield="id" visible="false"> <itemstyle verticalalign="top" /> </asp:boundfield> <asp:boundfield datafield="patient id" headertext="patient id"> <itemstyle verticalalign="top" /> </asp:boundfield> <asp:boundfield datafield="patient name" headertext="patient name"> <itemstyle verticalalign="top" /> </asp:boundfield> <asp:commandfield showdeletebutton="true" buttontype="button" /> <%--<asp:templatefield showheader="false"> <itemtemplate> <asp:button runat="server" text="delete" commandname="delete" onclientclick="return confirm('are sure want delete event?');" alternatetext="delete" /> </itemtemplate> </asp:templatefield>--%> </columns> </asp:gridview> aspx code
protected void gridview1_rowdeleting(object sender, system.web.ui.webcontrols.gridviewdeleteeventargs e) { try { string result = string.empty; int pid_cancellation_id = convert.toint32(gridview1.datakeys[e.rowindex].values[0]); result = new dal_pid_cancellation().set_pid_cancelled_flag(pid_cancellation_id, session["username"].tostring()); if(result == "1") { get_cancel_pid(); return; } else { get_cancel_pid(); return; } } catch (exception) { throw; } } how can call onrowdeleting method using asp:templatefield , show confirmation message on delete button press?
Comments
Post a Comment