dropdown list

  • 13 years ago

    hye...my scenario like this...i have 2 drop down list.... when user select the first ddp list...the value in the second value will be change according the selected value in the first ddp list... my first ddl list is package type ex;nature,island...and my second ddp list listed the location... when the user select value nature...then the second ddp list will list the location which include the package type = nature only.....

    coding :

    //this code for my first ddl list

    private void Fill_ddladdpackagestypes()

    {

    OleDbCommand cmd = new OleDbCommand(

    "SELECT package_type FROM package_master",

    con);

    con.Open();

    OleDbDataReader dr = cmd.ExecuteReader();

    while(dr.Read())

    {

    ddladdpackagestypes.Items.Add(Convert.ToString(dr.GetValue(0)));

    }

    dr.Close();

    con.Close();

    }

    //this code for my second ddp list

    private void Fill_location()

    {

    string strConn = Application["tourism_Connection"].ToString();

    SqlConnection con =

    new SqlConnection(strConn);

    string cmd = "SELECT location_name FROM package_location WHERE package_type = '" + Convert.ToString(ddladdpackagestypes.SelectedValue) + "'";

    SqlCommand cmd2 =

    new SqlCommand(cmd, con);

    con.Open();

    SqlDataReader dre = cmd2.ExecuteReader();

    while(dre.Read())

    {

    ddlLocation2.Items.Add(Convert.ToString(dre.GetValue(0)));

    }

    dre.Close();

    con.Close();

    }

    Please help me....

  • 13 years ago

    Are  you getting any error message or any problem with Dropdown list . What is happening

  • 13 years ago
    Hi
     In the first method "
    Fill_ddladdpackagestypes()" itslef you did the mistake.
    In this method you are adding only the text for the ddl you are not adding any value, then how can u get the "selectedvalue" of first ddl for the second ddl...

    I hope this may solve your problem.

    Good Luck

    Regards
    Hari K......









Post a reply

Enter your message below

Sign in or Join us (it's free).

Contribute

Why not write for us? Or you could submit an event or a user group in your area. Alternatively just tell us what you think!

Our tools

We've got automatic conversion tools to convert C# to VB.NET, VB.NET to C#. Also you can compress javascript and compress css and generate sql connection strings.

“C++ : Where friends have access to your private members.” - Gavin Russell Baker