Click here to Skip to main content
15,886,067 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
XML
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#

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
Comments
vishal.shimpi 27-Feb-13 4:01am    
what is code for stored Procedure?
$ultaNn 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));
}
$ultaNn 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)



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