asp.net - Client Deletion Confirmation -



asp.net - Client Deletion Confirmation -

i have "delete" alternative showing on gridview populated via sql info source. trying implement way user asked verify wish delete row of information. have been next guide http://msdn.microsoft.com/en-us/library/ms972940.aspx.

the issue i'm having when add together objectdatasource, select class , when go take desired method not listed (fig. 37).

addition info - created gridview populated via sqldatasource, i'm trying transition on objectdatasource , add together deletemethod. stuck @ part , not yet have popup window inquire user continue. work on after overcome current challenge.

here aspx code:

<asp:content id="content1" contentplaceholderid="headcontentadmin" runat="server"> </asp:content> <asp:content id="content2" contentplaceholderid="maincontentadmin" runat="server"> <asp:gridview id="gridview1" runat="server" autogeneratecolumns="false" cellpadding="4" datakeynames="coursesection_id" datasourceid="sqldatasource1" forecolor="#333333" gridlines="none"> <alternatingrowstyle backcolor="white" forecolor="#284775" /> <columns> <asp:commandfield showdeletebutton="true" showeditbutton="true" /> <asp:boundfield datafield="coursesection_id" headertext="coursesection_id" insertvisible="false" readonly="true" sortexpression="coursesection_id" /> <asp:boundfield datafield="section" headertext="section" sortexpression="section" /> </columns> <editrowstyle backcolor="#999999" /> <footerstyle backcolor="#5d7b9d" font-bold="true" forecolor="white" /> <headerstyle backcolor="#5d7b9d" font-bold="true" forecolor="white" /> <pagerstyle backcolor="#284775" forecolor="white" horizontalalign="center" /> <rowstyle backcolor="#f7f6f3" forecolor="#333333" /> <selectedrowstyle backcolor="#e2ded6" font-bold="true" forecolor="#333333" /> <sortedascendingcellstyle backcolor="#e9e7e2" /> <sortedascendingheaderstyle backcolor="#506c8c" /> <sorteddescendingcellstyle backcolor="#fffdf8" /> <sorteddescendingheaderstyle backcolor="#6f8dae" /> </asp:gridview> <asp:sqldatasource id="sqldatasource1" runat="server" connectionstring="<%$ connectionstrings:mgt598dbconnectionstring1 %>" selectcommand="select * [course_section]" deletecommand="delete [course_section] [coursesection_id] = @coursesection_id" insertcommand="insert [course_section] ([section]) values (@section)" updatecommand="update [course_section] set [section] = @section [coursesection_id] = @coursesection_id"> <deleteparameters> <asp:parameter name="coursesection_id" type="int32" /> </deleteparameters> <insertparameters> <asp:parameter name="section" type="string" /> </insertparameters> <updateparameters> <asp:parameter name="section" type="string" /> <asp:parameter name="coursesection_id" type="int32" /> </updateparameters> </asp:sqldatasource> <asp:objectdatasource id="objectdatasource1" runat="server"> </asp:objectdatasource> </asp:content>

my code behind file:

namespace mgt598graduateproject.view { public partial class viewcourse_section : system.web.ui.page { protected void page_load(object sender, eventargs e) { //http://msdn.microsoft.com/en-us/library/ms972940.aspx } public static void deletemethod(int coursesection_id) { // deletes specified order details record // northwind products table string sql = "delete [order details] orderid = " + "@orderid"; using (sqlconnection myconnection = new sqlconnection(configurationmanager.connectionstrings["mgt598dbconnectionstring1"].connectionstring)) { sqlcommand mycommand = new sqlcommand(sql, myconnection); mycommand.parameters.add(new sqlparameter("@coursesection_id", coursesection_id)); myconnection.open(); mycommand.executenonquery(); myconnection.close(); } } } }

there 2 issues here.

first, have few fundamental basics wrong.

you not need sqldatasource , objectdatasource.

as have pointed gridview sqldatasource (datasourceid="sqldatasource1") object info source infact useless.

you can delete next code aspx:

<asp:objectdatasource id="objectdatasource1" runat="server"> <asp:objectdatasource> </asp:content>

and delete entire deletemethod code behind.

if read tutorial linked see 2 seperate sections , not done together.

second, need have user 'verify' deletion.

to this, modify block match following:

<columns> <asp:templatefield> <itemtemplate> <asp:linkbutton id="linkbutton1" runat="server" onclientclick="return confirm('are sure want delete record?');" commandname="delete">delete item </asp:linkbutton> </itemtemplate> </asp:templatefield> <asp:commandfield showeditbutton="true" /> <asp:boundfield datafield="coursesection_id" headertext="coursesection_id" insertvisible="false" readonly="true" sortexpression="coursesection_id" /> <asp:boundfield datafield="section" headertext="section" sortexpression="section" /> </columns>

asp.net objectdatasource confirmation

Comments

Popular posts from this blog

How do I check if an insert was successful with MySQLdb in Python? -

delphi - blogger via idHTTP : error 400 bad request -

postgresql - ERROR: operator is not unique: unknown + unknown -