0

Hi,
I am having problem on getting value from dropDown list.

using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.OleDb;

public partial class _Default : System.Web.UI.Page 
{
    OleDbCommand comm;
    OleDbConnection conn;
    //conn = new OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=G:\\Demo11(1).accdb;Persist Security Info=False");
    
    
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {

            connectionAndData();
          
        }
    }

    private void connectionAndData()
    {
        conn = new OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=G:\\Demo11(1).accdb;Persist Security Info=False");
        try
        {
            conn.Open();
            Label1.Text = "Connection Esatblished";
            if (!IsPostBack)
            {
                comm = new OleDbCommand("select w2k_id from Employee", conn);
                OleDbDataReader rd = comm.ExecuteReader();
                while (rd.Read())
                {
                    DropDownList1.Items.Add(rd["w2k_id"].ToString());
                }
            }

        }
        catch (Exception exp)
        {
            Label1.Text = exp.ToString();
        }
    }

    protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
    {

        Label2.Text += DropDownList1.SelectedItem.Value.ToString();
    }
  
}

Problem is, no data is showing when a value is selected from dropdown List in protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e).

Can any one help me,,,,its very urgent...

2
Contributors
2
Replies
3
Views
6 Years
Discussion Span
Last Post by six_sic6
0

Is AutoPostBack set to true? Otherwise you may not be calling the SelectedIndexChanged method. You have the onclick="" element of the dropdownlist set correctly?

0

Is AutoPostBack set to true? Otherwise you may not be calling the SelectedIndexChanged method. You have the onclick="" element of the dropdownlist set correctly?

I had some other problems too, which are affecting this. I solved those and the problem is sloved. :)

Thank You for your reply

This question has already been answered. 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.