c# - Dropdownlist in edit mode of a gridview -
in application in c#, when edit row in gridview choose new data dropdownlist.
i populating dropdown this:
<asp:templatefield headertext="gender"> <itemtemplate> <asp:label id="gender" runat="server" text='<%# eval("gender").tostring() %>'></asp:label> </itemtemplate> <edititemtemplate> <asp:dropdownlist id="ddl_genderlist" runat="server"> <asp:listitem value="" text="---"></asp:listitem> <asp:listitem value="m" text="m"> </asp:listitem> <asp:listitem value="f" text="f"> </asp:listitem> </asp:dropdownlist> </edititemtemplate> </asp:templatefield>
but when press 'edit' button template , enters in 'rowupdating' event, selected value dropdownlist every time first value dropdownlist.
i need selected value in dropdownlist it's value displays in label gender.
does have ideas?
i've tried many ways set selected value in 'rowdatabound' event, no luck.
i tried this:
protected void gvproducts_rowdatabound(object sender, gridviewroweventargs e) { datarowview drowview = (datarowview)e.row.dataitem; if ((e.row.rowstate & datacontrolrowstate.edit) > 0) { dropdownlist genderlist = (dropdownlist)e.row.findcontrol("ddl_genderlist"); genderlist.selectedvalue = drowview[1].tostring(); } }
Comments
Post a Comment