asp.net - Which gridview event to use to add items to the dropdownlist used in the edit template? -
i show different values in dropdownlist, while editing gridview, depending on user logged in. example...
the officer see "approved officer" status. director see "approved director" status
i trying add these programatically dropdownlist have in edit template of gridview (approvalsgrid). here code:
protected sub approvalsgrid_rowupdating(byval sender object, byval e system.web.ui.webcontrols.gridviewupdateeventargs) handles approvalsgrid.rowupdating dim approvaleditdd dropdownlist = ctype(approvalsgrid.rows(approvalsgrid.editindex).findcontrol("approvaledit"), dropdownlist) if user.identity.name = "officer" approvaleditdd.items.add("approved officer") end if end sub
i not errors. empty dropdown no items. using correct event?
why not try this
<script runat=server> string getapprovedby() { if (user.identity.name == "officer") { return "approved officer"; } else if(user.identity.name == "some other name") { return "something else"; } else return string.empty; } </script> <asp:gridview runat="server"> <columns> <asp:templatefield> <edititemtemplate> <asp:dropdownlist runat="server"> <asp:listitem text='<%= getapprovedby() %>' /> </asp:dropdownlist> </edititemtemplate> </asp:templatefield> </columns> </asp:gridview>
this of course works if each user type have associated drop down item. fit needs?
Comments
Post a Comment