ASP.NET C# - Refresh 2nd DropdownList based on select of 1st dropdownlist

Assotanah

New Member
I am new to ASP.NETI have this code Page1.aspx for the DetailsView:\[code\] <InsertItemTemplate> <asp:DropDownList id="VendorName" datasourceid="VendorSqlDataSource" datatextfield="VendorName" DataValueField="VendorID" SelectedValue='http://stackoverflow.com/questions/12774483/<%# Bind("VendorID") %>' runat="server" AutoPostBack="true" /> </InsertItemTemplate> <EditItemTemplate> <asp:DropDownList id="VendorName" datasourceid="VendorSqlDataSource" datatextfield="VendorName" DataValueField="VendorID" SelectedValue='http://stackoverflow.com/questions/12774483/<%# Bind("VendorID") %>' runat="server" OnSelectedIndexChanged="dllVendor_OnSelectedIndexChanged" AutoPostBack="true" /> </EditItemTemplate> </asp:TemplateField> <asp:TemplateField HeaderText="Vendor BU"> <ItemTemplate> <asp:Label ID="VendorBUName" runat="Server" style="text-align:left; width:100%" Text='<%# Eval("VendorBUName")%>' Width="70%"/> </ItemTemplate> <InsertItemTemplate> <asp:DropDownList id="VendorBUName" datasourceid="VendorBUSqlDataSource" datatextfield="VendorBUName" DataValueField="VendorBUID" SelectedValue='http://stackoverflow.com/questions/12774483/<%# Bind("VendorBUID") %>' runat="server"/> </InsertItemTemplate> <EditItemTemplate> <asp:DropDownList id="VendorBUName" datasourceid="VendorBUSqlDataSource" datatextfield="VendorBUName" DataValueField="VendorBUID" SelectedValue='http://stackoverflow.com/questions/12774483/<%# Bind("VendorBUID") %>' runat="server"/> </EditItemTemplate> </asp:TemplateField>\[/code\]I am trying to make the code behind Page1.aspx.cs to refresh the 2nd Dropdown List in this code behind:\[code\](VendorBUName"), but keeps getting a error "". protected void OnSelectedIndexChanged(object VendorID) { string queryString = "SELECT VendorBUID, VendorBUName From MDF_VendorBU WHERE VendorID = @VendorID"; System.Data.SqlClient.SqlConnection connection = new System.Data.SqlClient.SqlConnection("ConnectionString"); System.Data.SqlClient.SqlCommand command = new System.Data.SqlClient.SqlCommand(queryString, connection); command.Parameters.AddWithValue("@VendorID", VendorID); connection.Open(); DataTable dt = new DataTable(); SqlDataAdapter ad = new SqlDataAdapter(command); ad.Fill(dt); /* VendorBUName.Items.Clear(); if (dt.Rows.Count > 0) { VendorBUName.DataSource = dt; VendorBUName.DataTextField = "VendorBUName"; VendorBUName.DataValueField = "VendorBUID"; VendorBUName.DataBind(); } */ connection.Close(); } //protected void dllVendor_OnSelectedIndexChanged(object sender, System.EventArgs e) //{ //OnSelectedIndexChanged(VendorName.SelectedValue.ToString()); //}\[/code\]I am keep getting the "The name 'VendorBUName' does not exist in the current context", looks like code behind is not recognize the 2nd dropdownlist in the Page1.aspxPlease help.
 
Back
Top