Set SelectCommand of Formview DrowDownList DataSourceControl

asafe

New Member
I need to set the SelectCommand for a data control source that is for a dropdownlist control inside a formview. I've not been able to locate an example online or anyone else inquiring.backgroundI have a drop down list that displays a list of customers that has a datasource not related to the formview control. I want the user to be able to choose a name from that combobox and then pass the underlying ID to the database with the other fields (not included in the example) in the formview to the database for insert. I need this control to display a list of customers when the page loads.an illustration: \[code\]FormView Control Drop Down Control with srcCustomer (data source control) ^^^^^^^^^^----I need to refer to this/FormView Control\[/code\]problemI am unable to "see" the SelectCommand of the srcCustomer data source control in my pageload event. It is buried within the formview control. I don't know the syntax to retrieve it.I have used this logic for a drop down list on an asp.net page but never embedded within a formview -- or for a control within a formview. Apparently no one else has ever had problems doing this (I find that difficult to believe, but I can't find any word of it here or elsewhere online.)So here is my asp.net:\[code\]<asp:FormView ID="fvwAddAction" runat="server" DataSourceID="srcAddAction" DataKeyNames="ActionID"><InsertItemTemplate><table><tr><td>Customer:</td><td><asp:DropDownList ID="ddlActionInsCustomer" runat="server" DataSourceID="srcCustomer" DataTextField="CustomerName" DataValueField="CustomerId" ></asp:DropDownList><asp:SqlDataSource ID="srcCustomer" runat="server" ConnectionString="<%$ ConnectionStrings:MyConnectionString %>" SelectCommand="sproc_GetCustomers" SelectCommandType="StoredProcedure" ><SelectParameters><asp:CookieParameter CookieName='userCookie("RepID").ToString' Name="repID" Type="Int32" /></SelectParameters></asp:SqlDataSource></td></tr></tr></table></InsertItemTemplate></asp:FormView>\[/code\]And here is my Code Behind:\[code\]Protected Sub Page_Load(sender As Object, e As System.EventArgs) Handles Me.LoadDim srcCustomer As DataSourceControl = fvwAddAction.FindControl("srcCustomer")Dim userCookie As HttpCookieuserCookie = Request.Cookies("RepID")If userCookie Is Nothing ThenResponse.Redirect("Default.aspx")End IffvwAddAction.ChangeMode(FormViewMode.Insert)srcCustomer.SelectCommand = "sproc_GetCustomers"srcCustomer.SelectCommandType = SqlDataSourceCommandType.StoredProceduresrcCustomer.SelectParameters("RepID").DefaultValue = http://stackoverflow.com/questions/14470509/userCookie("RepID").ToStringEnd Sub\[/code\]
 
Back
Top