Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C#1.0 C#2.0 C#3.0 ASP ASP.NET C#4.0 , +
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
Lubnash811
Comments
vishal.shimpi at 27-Feb-13 4:01am
   
what is code for stored Procedure?
Lubnash at 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 at 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 at 10-Mar-13 3:15am
   
Thanks it work fine...
Gian rebollido at 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
0 OriginalGriff 504
1 Gihan Liyanage 298
2 RyanDev 250
3 Sergey Alexandrovich Kryukov 223
4 Richard Deeming 195
0 Sergey Alexandrovich Kryukov 8,906
1 OriginalGriff 7,771
2 CPallini 2,603
3 Richard MacCutchan 2,121
4 Abhinav S 1,928


Advertise | Privacy | Mobile
Web03 | 2.8.140827.1 | Last Updated 27 Feb 2013
Copyright © CodeProject, 1999-2014
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