Click here to Skip to main content
14,735,205 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi there

i have tree dropdownlist in one page also (ok) button click event.
all dropdown data comes from database.

1 dropdown for standard
2 dropdown for subject
3 dropdown for chapter

when i click on ok button then 3rd dropdown always automatically select first value from list.
i also have fileupload control in same page.


//on page load event
if (!Page.IsPostBack)

public void FillClass()
        string com = "Select * from Class";
        SqlDataAdapter adpt = new SqlDataAdapter(com, cn);
        DataTable dt = new DataTable();
        DropDownList1.DataSource = dt;
        DropDownList1.DataTextField = "classname";
        DropDownList1.DataValueField = "srno";
        DropDownList1.Items.Insert(0, new ListItem("--Select--", "0"));

protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
            string com = "Select * from SubjectName where std='" + DropDownList1.SelectedItem.Text + "'";
            SqlDataAdapter adpt = new SqlDataAdapter(com, cn);
            DataTable dt = new DataTable();
            DropDownList2.DataSource = dt;
            DropDownList2.DataTextField = "subject";
            DropDownList2.DataValueField = "srno";
            DropDownList2.Items.Insert(0, new ListItem("--Select--", "0"));
protected void DropDownList2_SelectedIndexChanged(object sender, EventArgs e)

            string com = "Select * from Chapter where std='" + DropDownList1.SelectedItem.Text + "' and subject='" + DropDownList2.SelectedItem.Text + "'";
            SqlDataAdapter adpt = new SqlDataAdapter(com, cn);
            DataTable dt = new DataTable();
            DropDownList3.DataSource = dt;
            DropDownList3.DataTextField = "chapter";
            DropDownList3.DataValueField = "srno";
            DropDownList3.Items.Insert(0, new ListItem("--Select--", "0"));
    protected void Button1_Click(object sender, EventArgs e)
        Label1.Text = DropDownList3.Text;       

<%@ Page Title="" Language="C#" MasterPageFile="~/admin/AdminMasterPage.master" AutoEventWireup="true" CodeFile="papergenr.aspx.cs" Inherits="admin_papergenr" %>

<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">

<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">

    <asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="True" 


    <asp:DropDownList ID="DropDownList2" runat="server" AutoPostBack="True" 


    <asp:DropDownList ID="DropDownList3" runat="server">

    <br />
 <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
    <br />
    <asp:Button ID="Button1" runat="server" Text="Button" onclick="Button1_Click" />

Updated 25-Jun-15 1:46am
sasanka sekhar panda 25-Jun-15 0:39am
Please post the code inside the button click event...
Member 11422010 25-Jun-15 4:29am
please try.
sasanka sekhar panda 25-Jun-15 4:38am
page load event is their any more lines of code that u did not post..
Member 11422010 25-Jun-15 4:51am
no only one line.
Member 11422010 25-Jun-15 4:58am
if you dont have any problem then. i can give teamviewer access.
sasanka sekhar panda 25-Jun-15 5:51am
On the Text of lebel4 you are getting ---select-- after button1 click but you need the selected "chapter" from dropdown3..This is what my understanding??

If i m correct then
please send all the code and designer file of that page...But I do not see any problem with your code...
Member 11422010 25-Jun-15 6:06am
no i am getting chapter 1 which is below the -----select-----
sasanka sekhar panda 25-Jun-15 5:57am
put a break point in DropDownList2_SelectedIndexChanged event and tell me is it executed
when you are clicking the button..
Member 11422010 25-Jun-15 6:06am
nop its not execute
sasanka sekhar panda 25-Jun-15 6:34am
please share the source code of design..Quick..
Member 11422010 25-Jun-15 6:47am
source code uploaded plz check
sasanka sekhar panda 25-Jun-15 6:48am
its looking fine..In SelectedIndexChanged of dropdown2 , you get all the chapters in dropdown3 according to your query or not ??
Member 11422010 25-Jun-15 6:52am
yes i get.
sasanka sekhar panda 25-Jun-15 7:06am
I tried ur logic in three dropdown they are working fine...Sorry dear..
You realy dont need to
cn.Close(); cn.Open(); remove them from everywhere where you are fetching or selecting records...But it wo not solve your problem..You create a new page and try the things from beginning..It may help u...

1 solution

Make sure that-
1. If you have written the logic to bind dropdownlist list in the page load event then you must write the check for post back. Following code block may help
   // logic for binding dropdownlist 

2. Make sure that you haven't written any logic for binding dropdownlist in the OK button click event unless it is really required.

If this doesn't solve you problem, please update your question with the respective code so that actual solution can be suggested.

Hope, it helps :)
Member 11422010 24-Jun-15 23:47pm
solution not work.
i have updated question with code.
Suvendu Shekhar Giri 25-Jun-15 1:03am
Code for Button click event is also required to give the correct solution. Please update your answer.
Member 11422010 25-Jun-15 1:14am

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