Click here to Skip to main content
12,953,175 members (45,968 online)
Rate this:
 
Please Sign up or sign in to vote.
i want to use cascading dropdownlist its like this
 
i have one dropdown \
 
Hardware
 
software
 
Network
 
when i click network its should only display dropdown list of network problems same for software and Hardware
 
i am trying like this
 
Aspx
 
<pre lang="HTML">
 
 <asp:DropDownList ID="PRB_type_ddl" runat="server"
                    DataTextField="prob_type"
                    DataValueField="prob_type" Height="20px" Width="114px"
    onselectedindexchanged="DropDownList3_SelectedIndexChanged1" AutoPostBack="True"
                    >
                            <asp:ListItem>--Select--</asp:ListItem>
                            <asp:ListItem>Hardware</asp:ListItem>
                            <asp:ListItem>Software</asp:ListItem>
                            <asp:ListItem>Network</asp:ListItem>
                        </asp:DropDownList>
                        <br />
 

            </td>
            <td class="style33">
        <span class="style28">
                        <asp:DropDownList ID="Hard_ddl" runat="server"
                            DataTextField="Hardware"
                            DataValueField="Hardware" DataSourceID="SqlDataSource3">
                        </asp:DropDownList>
 

                <asp:SqlDataSource ID="SqlDataSource3" runat="server"
                    ConnectionString="<%$ ConnectionStrings:con %>"
                    SelectCommand="SELECT [Hardware] FROM [p_type]"></asp:SqlDataSource>
 

                <asp:DropDownList ID="Soft_ddl" runat="server"
                   DataTextField="Software"
                    DataValueField="Software" DataSourceID="SqlDataSource5">
                </asp:DropDownList>
                <asp:SqlDataSource ID="SqlDataSource5" runat="server"
                    ConnectionString="<%$ ConnectionStrings:con %>"
                    SelectCommand="SELECT [Software] FROM [p_type]"></asp:SqlDataSource>
                <asp:DropDownList ID="OP_ddl" runat="server"
                    DataTextField="Operating_system"
                    DataValueField="Operating_system" DataSourceID="SqlDataSource6">
                </asp:DropDownList>
 
                <asp:SqlDataSource ID="SqlDataSource7" runat="server"
                    ConnectionString="<%$ ConnectionStrings:con %>"
                    SelectCommand="SELECT [Net_work] FROM [p_type]"></asp:SqlDataSource>
c#

protected void DropDownList3_SelectedIndexChanged1(object sender, EventArgs e)
    {
 
        if (PRB_type_ddl.SelectedValue == "Hardware")
        {
            Hard_ddl.Visible = true;
            Soft_ddl.Visible = false;
            NET_ddl.Visible = false;
            Soft_ddl.SelectedIndex = -1;
            NET_ddl.SelectedIndex = -1;
 

 
        }
 

        else if (PRB_type_ddl.SelectedValue == "Software")
        {
            Soft_ddl.Visible = true;
            NET_ddl.Visible = false;
            Hard_ddl.Visible = false;
 
            Hard_ddl.SelectedIndex = -1;
            NET_ddl.SelectedIndex = -1;
        }
        else
        {
            NET_ddl.Visible = true;
            Hard_ddl.Visible = false;
 
            Soft_ddl.Visible = false;
 
            Soft_ddl.SelectedIndex = -1;
            Hard_ddl.SelectedIndex = -1;
        }
 
    }
 

 

                    con.Open();
                    SqlCommand cmd = new SqlCommand();
                    cmd.CommandType = CommandType.StoredProcedure;
                    cmd.CommandText = "Tech_sup";
                    cmd.Parameters.AddWithValue("@Build_name", Build.Text);
                    cmd.Parameters.AddWithValue("@Dept", DropDownList2.Text);
                     if (string.IsNullOrEmpty(Hard_ddl.Text))
                    {
                        cmd.Parameters.Add(new SqlParameter("@P_type", DBNull.Value.ToString()));
                    }
                    else
                    {
                        cmd.Parameters.Add(new SqlParameter("@P_type", Hard_ddl.Text));
                    }
                    if (string.IsNullOrEmpty(Soft_ddl.Text))
                    {
                        cmd.Parameters.Add(new SqlParameter("@P_type", DBNull.Value.ToString()));
                    }
                    else
                    {
                        cmd.Parameters.Add(new SqlParameter("@P_type", Soft_ddl.Text));
                    }
 
                    if (string.IsNullOrEmpty(NET_ddl.Text))
                    {
                        cmd.Parameters.Add(new SqlParameter("@P_type", DBNull.Value.ToString()));
                    }
                    else
                    {
                        cmd.Parameters.Add(new SqlParameter("@P_type", NET_ddl.Text));
                    }
                    cmd.Connection = con;
                    cmd.ExecuteNonQuery();
                    con.Close();
Posted 26-Feb-13 21:44pm
$ultaNn733
Comments
vishal.shimpi 27-Feb-13 4:01am
   
what is code for stored Procedure?
Lubnash 27-Feb-13 4:07am
   
ALTER PROCEDURE [dbo].[Tech_sup]

(


@Build_name varchar(max),
@Dept varchar(max),
@P_type varchar (50),
@id int output



)
AS
BEGIN

set @id = 0
INSERT INTO dbo.Tech_data (Build_name,Dept,P_type)
values (@Build_name,@Dept,@P_type)
set @id = Scope_identity()

END
vishal.shimpi 27-Feb-13 4:13am
   
use
if(!string.IsNullOrEmpty(Hard_ddl.Text))
{
cmd.Parameters.Add(new SqlParameter("@P_type", Hard_ddl.Text));
}
instead of (replace all if else with only if that i suggested)
if (string.IsNullOrEmpty(Hard_ddl.Text))
{
cmd.Parameters.Add(new SqlParameter("@P_type", DBNull.Value.ToString()));
}
else
{
cmd.Parameters.Add(new SqlParameter("@P_type", Hard_ddl.Text));
}
Lubnash 10-Mar-13 3:15am
   
Thanks it work fine...
Gian rebollido 26-Mar-13 1:23am
   
try to debug your code.. then see what is the problem..

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

    Print Answers RSS
Top Experts
Last 24hrsThis month
OriginalGriff 6,429
CHill60 3,490
Maciej Los 3,103
Jochen Arndt 1,975
ppolymorphe 1,920


Advertise | Privacy | Mobile
Web02 | 2.8.170525.1 | Last Updated 27 Feb 2013
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100