asp.net - Deleting is not supported by data source 'SqlDataSource1' in c# -
this cs:
protected void gridview1_rowcommand(object sender, gridviewcommandeventargs e) { sqlconnection con = connection.dbconnection(); if (e.commandname == "editrow") { gridviewrow gr = (gridviewrow)((button)e.commandsource).namingcontainer; textid.text = gr.cells[0].text; textusername.text = gr.cells[1].text; textclass.text = gr.cells[2].text; textsection.text = gr.cells[3].text; textaddress.text = gr.cells[4].text; } else if (e.commandname == "deleterow") { gridviewrow gr = (gridviewrow)((button)e.commandsource).namingcontainer; sqlcommand com = new sqlcommand("storedprocedure4", con); com.commandtype = commandtype.storedprocedure; com.parameters.addwithvalue("@id", gr.cells[0].text); var id = int32.parse(e.commandargument.tostring()); gridview1.deleterow(id); com.executenonquery(); } }
i created student details form, want delete row gridview
.
when click delete, shows following error:
deleting not supported data source 'sqldatasource1' unless deletecommand specified.
i'm new .net. getting started,
may know, mistake in above code?
thanks,
else if (e.commandname == "deleterow") { gridviewrow gr = (gridviewrow)((button)e.commandsource).namingcontainer; sqlcommand com = new sqlcommand("storedprocedure4", con); com.commandtype = commandtype.storedprocedure; com.parameters.addwithvalue("@id", gr.cells[0].text); var id = int32.parse(e.commandargument.tostring()); //comment or remove below line //gridview1.deleterow(id); com.executenonquery(); //rebind data after delete gridview1.databind(); }
Comments
Post a Comment