2
Answers

C #Working with Dropdown lists

Ask a question
Hi there,

I'm net to C#, .net, visual studio, so please excuse me if my questions are a little stupid.

I am trying to create a webform and am confused as to how the data is collected from a Dropdown list.

The code I have is;

 protected void Page_Load(object sender, EventArgs e)

        {
            string strConn = "Data Source=test-sql-01;Initial Catalog=IEG4; User ID=; Password=";
            SqlConnection conn = new SqlConnection(strConn);
            SqlDataAdapter daStatus = new SqlDataAdapter("select [Status] from [Council Tax Status]", conn);
            DataSet dsStatus = new DataSet();
            daStatus.Fill(dsStatus);
            lstStatus.DataSource = dsStatus;
            lstStatus.DataTextField = "Status";
            lstStatus.DataBind();
         }

         protected void lstStatus_SelectedIndexChanged(object sender, EventArgs e)
        {

            lblStatus.Text = lstStatus.SelectedValue;
          
        }

When the value selected in the Dropdown box is changed the text value of the label does not change

Can anyone point me in the right direction?

Thanks





Answers (2)