.net - Update gridview row with separately bound dropdownlist -


i have ddl in gridview bound separately rest of gridview. want update sql database based on ddl, error, "could not find control 'ddlusers' in controlparameter ''."

public sub bindgridview()     'bind gridview     sqldatasource1.selectcommand = "select * leadership left outer join customer on leadership.customerid = customer.customerid"     sqldatasource1.databind()      'binding dropdownlist inside of gridview     sqldatasource2.selectcommand = "select lname + ', ' + fname name, customerid customer active = 'true' , probation = 'false' order lname asc"     sqldatasource2.databind()  end sub  protected sub gridview1_rowupdating(sender object, e gridviewupdateeventargs)     dim ddl dropdownlist = directcast(gridview1.rows(e.rowindex).findcontrol("ddlusers"), dropdownlist)      dim constr string = "data source=mydatasource"     dim cn new sqlconnection(constr)     cn.open()     dim updcmd new sqlcommand("updateleadership", cn)     updcmd.commandtype = commandtype.storedprocedure     updcmd.parameters.add("@customerid", sqldbtype.int).value = ddl.selectedvalue.tostring()     updcmd.parameters.add("@position", sqldbtype.nvarchar).value = ddl.selecteditem.tostring()      sqldatasource1.databind()     updcmd.parameters.clear()     bindgridview() end sub 

then gridview

<asp:gridview id="gridview1" runat="server" onrowupdating="gridview1_rowupdating" datasourceid="sqldatasource1" datakeynames="id">                   <columns>         <asp:templatefield>             <headerstyle width="5%" />             <itemstyle width="5%" />             <edititemtemplate>                 <asp:linkbutton id="btncancel" text="cancel" runat="server" commandname="cancel" />                 <asp:linkbutton id="btnupdate" runat="server" commandname="update" onclientclick="return confirm('are sure you're sure want update position?');">update</asp:linkbutton>                   </edititemtemplate>                         <itemtemplate>                 <asp:linkbutton id="linkbutton2" runat="server" onclientclick="return confirm('are sure want update position?');"                                 commandname="edit">change</asp:linkbutton>                              </itemtemplate>         </asp:templatefield>              <asp:templatefield headertext="position" >                             <itemtemplate>                 <asp:label runat="server" id="president" text ='<%# eval("position")%>'></asp:label>             </itemtemplate>         </asp:templatefield>                     <asp:templatefield headertext="member name" >             <edititemtemplate>                 <asp:dropdownlist id="ddlusers" runat="server" datasourceid="sqldatasource2" appenddatabounditems="true" datatextfield="name" datavaluefield="customerid" autopostback="true"></asp:dropdownlist>             </edititemtemplate>             <itemtemplate>                 <asp:label runat="server" id="lblfirstvice" text ='<%# eval("fname") & " " & eval("lname")%>'></asp:label>             </itemtemplate>         </asp:templatefield>                 </columns>     <rowstyle backcolor="#dedfde" forecolor="black" />     <selectedrowstyle backcolor="#9471de" font-bold="true" forecolor="white" />     <pagerstyle backcolor="#c6c3c6" forecolor="black" horizontalalign="right" />     <headerstyle backcolor="#4a3c8c" font-bold="true" forecolor="#e7e7ff" /> </asp:gridview>          <asp:sqldatasource id="sqldatasource1" runat="server" connectionstring="<%$ connectionstrings:ncoaconnectionstring %>" updatecommand="updateleadership" updatecommandtype="storedprocedure">                        <updateparameters>         <asp:controlparameter controlid="ddlusers" propertyname="selectedvalue" type="int32" />      </updateparameters>     </asp:sqldatasource>  <asp:sqldatasource id="sqldatasource2" runat="server" connectionstring="<%$ connectionstrings:ncoaconnectionstring %>"> </asp:sqldatasource> 


Comments

Popular posts from this blog

c# - How Configure Devart dotConnect for SQLite Code First? -

java - Copying object fields -

c++ - Clear the memory after returning a vector in a function -