c# - How do I maintain the selected item in GridView DropDownList -
my problem not able retain item in gridview after gridview_rowediting event.
<asp:templatefield headerstyle-cssclass="gridheading" headertext="get alerts sms" itemstyle-cssclass="gridvalue" itemstyle-horizontalalign="center"> <itemtemplate> <asp:label id="lblalertbysmsgeofence" runat="server" text=' <%# (convert.toboolean(convert.toint32(eval("alertbysms")))) ? "yes" : "no" %>'></asp:label> </itemtemplate> <edititemtemplate> <asp:dropdownlist id="ddlalertbysmsgeofence" runat="server" appenddatabounditems="true" cssclass="gridvalue"> <asp:listitem text="yes" value="1"/> <asp:listitem text="no" value="0" /> </asp:dropdownlist> </edititemtemplate> <headerstyle cssclass="gridheading" /> <itemstyle cssclass="gridvalue" horizontalalign="center" /> </asp:templatefield>
edit
protected void grdgeofence_rowediting(object sender, gridviewediteventargs e) { gridviewrow row = (gridviewrow)grdgeofence.rows[e.neweditindex]; grdgeofence.editindex = e.neweditindex; list<commongeofencealert> geofencedata = new blsmsalertdetail().getgeofencealertdetail(session["sessaccountid"].tostring(), txtdeviceid.text); (int y = 0; y < geofencedata.count; y++) { geofencedata[y].vehiclenumber = ddlvehiclenumber.selecteditem.text; } grdgeofence.datasource = geofencedata; grdgeofence.databind(); } protected void grdgeofence_rowupdating(object sender, gridviewupdateeventargs e) { gridviewrow row = (gridviewrow)grdgeofence.rows[e.rowindex]; string id = grdgeofence.datakeys[e.rowindex].value.tostring(); label lblvehicle = (label)row.findcontrol("lblvehiclegeofence"); textbox mobilenumber = (textbox)row.findcontrol("txtmobilegeofence"); textbox emailid = (textbox)row.findcontrol("txtemailgeofence"); dropdownlist ddlalertbysms = (dropdownlist)row.findcontrol("ddlalertbysmsgeofence"); dropdownlist ddlalertbyemail = (dropdownlist)row.findcontrol("ddlalertbyeemailgeofence"); dropdownlist alertatgeofenceenter = (dropdownlist)row.findcontrol("ddlalertgeofenceenter"); dropdownlist alertatgeofenceexit = (dropdownlist)row.findcontrol("ddlalertgeofenceexit"); dropdownlist ddladdress = (dropdownlist)row.findcontrol("ddlgeofenceaddressgrid"); blsmsalertdetail detail = new blsmsalertdetail(); int = updategeofence(id, mobilenumber.text, emailid.text, ddlalertbysms.selecteditem.value, ddlalertbyemail.selecteditem.value, alertatgeofenceenter.selecteditem.value, alertatgeofenceexit.selecteditem.value, ddladdress.selecteditem.text); if (i == 1) { scriptmanager.registerclientscriptblock(this.page, typeof(page), guid.newguid().tostring(), "alert('success!!')", true); } else { scriptmanager.registerclientscriptblock(this.page, typeof(page), guid.newguid().tostring(), "alert('error!! not update value.')", true); } grdgeofence.editindex = -1; list<commongeofencealert> geofencedata = new blsmsalertdetail().getgeofencealertdetail(session["sessaccountid"].tostring(), txtdeviceid.text); (int y = 0; y < geofencedata.count; y++) { geofencedata[y].vehiclenumber = ddlvehiclenumber.selecteditem.text; } grdgeofence.datasource = geofencedata; grdgeofence.databind(); } protected void grdgeofence_rowdatabound(object sender, gridviewroweventargs e) { if (grdgeofence.editindex == e.row.rowindex && e.row.rowtype == datacontrolrowtype.datarow) { dropdownlist ddladdress = (dropdownlist)e.row.cells[0].findcontrol("ddlgeofenceaddressgrid"); list<commonsmsalertdetail> getsmsdispatcherdata = new blsmsalertdetail().getsmsalertdetail(session["sessaccountid"].tostring()); (int = 0; < getsmsdispatcherdata.count; i++) { ddladdress.items.add(new listitem(getsmsdispatcherdata[i].place, getsmsdispatcherdata[i].place)); } //ddladdress.datasource = getsmsdispatcherdata; //ddladdress.datatextfield = "place"; //ddladdress.datavaluefield = "place"; //ddladdress.databind(); } }
the database return 0/1 depending upon situation , convert yes , no using boolean expressions.
i want keep value of "lblalertbysmsgeofence"
selected text of dropdownlist "ddlalertbysmsgeofence"
i have seen many solution of many websites including so. method lengthy , not in context situation. have around 100 dropdownlists , cannot rewrite code again , again..
is there simpler way it.?
add property selectedvalue='<%#eval("alertbysms")%>'
dropdowlist
ddlalertbysmsgeofence
. check link how set selectedvalue of dropdownlist in gridview edittemplate more details.
<edititemtemplate> <asp:dropdownlist id="ddlalertbysmsgeofence" runat="server" appenddatabounditems="true" selectedvalue='<%#eval("alertbysms")%>' cssclass="gridvalue"> <asp:listitem text="yes" value="1" /> <asp:listitem text="no" value="0" /> </asp:dropdownlist>
Comments
Post a Comment