c# - RowUpdating Event of Gridview is not working properly -
i wanted update table through gridview. [visual studio 2010]
for have done following:
gridview>> editcolumns >> commandfield >> edit,update,cancel added grid.
gridview>> edittemplates >> added textbox names "textbox1">>end editing template.
row editing event:
public int i; protected void gv_rowediting(object sender, gridviewediteventargs e) { i=gv.editindex = e.neweditindex; } row updating event:
protected void gv_rowupdating(object sender, gridviewupdateeventargs e) { try { textbox txtsymbol; txtsymbol = ((textbox)(gv.rows[e.rowindex].cells[3].findcontrol("textbox1"))); con.open(); cmd = new sqlcommand("update temp set symbol=@symbol", con); cmd.parameters.addwithvalue("@symbol",txtsymbol.text); cmd.executenonquery(); con.close(); } catch (exception ex) { } } i refered code here.
here mentioned th line should this:
txtsymbol = ((textbox)(gv.rows[e.rowindex].cells[3].findcontrol("textbox1")));
all coded thing not working.
`((textbox)(gv.rows[e.rowindex].cells[3].findcontrol("textbox1")))` is having null value.
gives exception in row updating event "null referance exception."
what wrong in code?
where making mistake.
please guid me.
protected void gv_rowediting(object sender, gridviewediteventargs e) { gv.editindex = e.neweditindex; bindgridview();//you have bind gridview again here... } if dont bind gridview again after setiing edit index control not bounded gridview.thats why giving null refrence exception.
Comments
Post a Comment