Last post Sep 21, 2010 07:06 AM by Zizhuoye Chen - MSFT
Sep 16, 2010 02:01 PM|cakerack|LINK
I am a complete newcomer to ASP.NET. However in the few weeks I have been playing with it I have got pretty far and have mastered things like stored procedures, gridviews, formviews and templates. I have come across a problem which I am struggling with
and could do with some help! The scenario is this:
I assumed it would simply be a case of modifying the select statement on SQLDataSource2 using the SelectedIndexChanged event on the first DropDownList to update the second SQL source, but I cannot work out for the life of me how to do it. Pretty much all
of the code I have is ASP.
Is there a way I can do this purely in ASP rather than using VB behind the scenes or do I need to use VB? I am pretty comfortable with vb.net but one of the other issues I have is referencing an ASP object from VB... so for instance if I had a text box
in ASP, how can I read or change the properties of this object from VB?
FYI I am using Visual Studio 2010 and SQL/Server
Any help much appreciated!!!
Sep 16, 2010 02:25 PM|sirdneo|LINK
YOu can use AJAX cascading dropdown to implement this, see this sample:-
Sep 16, 2010 02:33 PM|tamilcodes|LINK
when configuring the second sql data source, choose the control parameter as the previous ddl selected value. I hope you are just dragging and gdropping the ddl to create cascaded drop down list.
Sep 21, 2010 07:06 AM|Zizhuoye Chen - MSFT|LINK
We can use SqlDataSource.Parameter to input the sqlparameter in order to select value from cascade dropdownlist.
<form id="form1" runat="server">
<asp:DropDownList ID="DropDownList1" runat="server" DataSourceID="SqlDataSource1"
DataTextField="CategoryID" DataValueField="CategoryID" AutoPostBack="True" OnSelectedIndexChanged="DropDownList1_SelectedIndexChanged">
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:NorthwindConnectionString %>"
SelectCommand="SELECT [CategoryID] FROM [Categories] ORDER BY [CategoryID]">
<asp:DropDownList ID="DropDownList2" runat="server" DataTextField="CategoryName"
<asp:SqlDataSource ID="SqlDataSource2" runat="server" ConnectionString="<%$ ConnectionStrings:NorthwindConnectionString %>"
OnSelecting="SqlDataSource1_Selecting" SelectCommand="SELECT [CategoryID], [CategoryName] FROM [Categories] WHERE CategoryID = @CID ">
protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
this.SqlDataSource2.SelectParameters.Add("CID", DbType.Double, this.DropDownList1.SelectedValue);
this.DropDownList2.DataSourceID = "SqlDataSource2";
The table of "Categories" has colum named "CategoryID" and "CategoryName".
Hopes can help you.