0

I have two dropdownlists on my page containing semester number and subject names respectively.
When I select First semester from dropdownlist1 and click on go button then the dropdownlist2 contain subjects of first semester fetched from database in sqlserver.... it is working fine, but when i select semester Second from dropdownlist1 then dropdownlist2 is containing subjects of both semesters... same problem is with other semesters.. can someone plz help me how to solve it...

public partial class studentnew : System.Web.UI.Page

    SqlConnection con = new SqlConnection(@"server= rakesh-vaio\sqlexpress; database=qms;Integrated Security=True");
    SqlCommand cmd;
    DataTable dt;
    SqlDataReader dr;
    SqlDataAdapter da;

    protected void Page_Load(object sender, EventArgs e)
    {
    }
    protected void DropDownList2_SelectedIndexChanged(object sender, EventArgs e)
    {

    }
    protected void Button4_Click(object sender, EventArgs e)
    {
        con.Open();
        cmd = new SqlCommand("select QuizName from QuizMaster where Semester = ' " + DropDownList1.SelectedItem.Text + "'", con);
        dr = cmd.ExecuteReader();
        while (dr.Read())
        {
            if (DropDownList1.SelectedItem.Text == "FIRST")
            {
                 DropDownList2.Items.Add(dr.GetString(0));
            }

            if (DropDownList1.SelectedItem.Text == "SECOND")
            {

             DropDownList2.Items.Add(dr.GetString(0));
            }
            if (DropDownList1.SelectedItem.Text == "THIRD")
            {
               DropDownList2.Items.Add(dr.GetString(0));
            }
            if (DropDownList1.SelectedItem.Text == "FOURTH")
            {
                DropDownList2.Items.Add(dr.GetString(0));
            }
            if (DropDownList1.SelectedItem.Text == "FIFTH")
            {
               DropDownList2.Items.Add(dr.GetString(0));
            }         
        }

        //DropDownList2.SelectedIndex = 0;
        //DropDownList1.SelectedIndex = 0;
        con.Close();
        dr.Close();
    }


    I have two dropdownlists on my page containing semester number and subject names respectively.
    When I select First semester from dropdownlist1 and click on go button then the dropdownlist2 contain subjects of first semester fetched from database in sqlserver.... it is working fine, but when i select semester Second from dropdownlist1 then dropdownlist2 is containing subjects of both semesters... same problem is with other semesters.. can someone plz help me how to solve it...

    public partial class studentnew : System.Web.UI.Page
    {
        SqlConnection con = new SqlConnection(@"server= rakesh-vaio\sqlexpress; database=qms;Integrated Security=True");
        SqlCommand cmd;
        DataTable dt;
        SqlDataReader dr;
        SqlDataAdapter da;

        protected void Page_Load(object sender, EventArgs e)
        {
        }
        protected void DropDownList2_SelectedIndexChanged(object sender, EventArgs e)
        {

        }
        protected void Button4_Click(object sender, EventArgs e)
        {
            con.Open();
            cmd = new SqlCommand("select QuizName from QuizMaster where Semester = ' " + DropDownList1.SelectedItem.Text + "'", con);
            dr = cmd.ExecuteReader();
            while (dr.Read())
            {
                if (DropDownList1.SelectedItem.Text == "FIRST")
                {
                     DropDownList2.Items.Add(dr.GetString(0));
                }

                if (DropDownList1.SelectedItem.Text == "SECOND")
                {

                 DropDownList2.Items.Add(dr.GetString(0));
                }
                if (DropDownList1.SelectedItem.Text == "THIRD")
                {
                   DropDownList2.Items.Add(dr.GetString(0));
                }
                if (DropDownList1.SelectedItem.Text == "FOURTH")
                {
                    DropDownList2.Items.Add(dr.GetString(0));
                }
                if (DropDownList1.SelectedItem.Text == "FIFTH")
                {
                   DropDownList2.Items.Add(dr.GetString(0));
                }         
            }

            //DropDownList2.SelectedIndex = 0;
            //DropDownList1.SelectedIndex = 0;
            con.Close();
            dr.Close();
        }
    }
}

Edited by Dani: Formatting fixed

2
Contributors
1
Reply
14
Views
3 Years
Discussion Span
Last Post by ggamble
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.