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...

Recommended Answers

All 2 Replies

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

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

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.