Click here to Skip to main content
15,900,461 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
If one feild select from dropdown ie(IT) then we want to display all sub category which is related to that feild ie.(IT) in another dropdown..nd also same to other feild....so what can i do?????plz help me...
Posted

if you using data-binding on your page, and the sub category is related to the value from first drop down, there is too many way to implement.
easiest way is use a datasource like SQLdatasource, and use smart tag, and add a where clause state to your selection with a parameter from your first drop down selected value or other source like session,route,... like this:
XML
<asp:SqlDataSource ID="SqlDataSource2" runat="server"
ConnectionString="<%$ ConnectionStrings:testConnectionString %>"
SelectCommand="SELECT * FROM [orders] WHERE ([status_id] = @status_id)">
<SelectParameters>
<asp:ControlParameter ControlID="ddl1" DefaultValue="1" Name="status_id"
PropertyName="SelectedValue" Type="Int32" />


or you can use OnSelectedIndexChanged event for first databind, look at this code snipped:
C#
protected void ddl1_SelectedIndexChanged(object sender, EventArgs e)
        {
            var ds = (from a in DB.orders where status_id == ddl1.SelectedValue select a).ToList();
            ddl2.DataSource = ds;
        }

Next is use Linq DataSource and on selecting event handle your binding logic like this:
C#
protected void linqds_Selecting(object sender, LinqDataSourceSelectEventArgs e)
        {
            e.Result = (from a in DB.orders where status_id == ddl1.SelectedValue select a).ToList();
        }
 
Share this answer
 
Hi,
There is one event for dropdown - onselectedindexchange. You can use this event. On the selected index change of the first dropdown, pass the value of the first dropdown to the your load method, and fill the result to the next drop down.

Happy Coding :)
 
Share this answer
 
try like this

under page load event load the dropdown1 then bind dropdown2 under dropdownlist1 selected index changed event
EX:
VB
cmd = New SqlCommand(&quot;select * from sample&quot;, con)
        dr = cmd.ExecuteReader()

 DropDownList1.DataSource = dr
        DropDownList1.DataTextField = "name"
        DropDownList1.DataValueField = "name"

        DropDownList1.DataBind()
        dr.Close()
        con.Close()


under dropdownlist1 selected index changed event
VB
Protected Sub DropDownList1_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles DropDownList1.SelectedIndexChanged
        con.Open()
        cmd = New SqlCommand("select * from sample1 where name='" + DropDownList1.SelectedItem.ToString() + "' ", con)
        dr = cmd.ExecuteReader()
        DropDownList2.DataSource = dr
        DropDownList2.DataTextField = "name"
        DropDownList2.DataValueField = "name"

        DropDownList2.DataBind()
        dr.Close()
        con.Close()

  End Sub
 
Share this answer
 
use OnSelectedIndexChanged event for this. when change the data of list than on this event fill your next dropdownlist.
same do other dropdownlists
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900