Hey everyone,

I'm using C# ASP.NET and am trying to bind a field in my SQL database to a label. I have a combo box working OK with my database right now, and I want the label to change when the combo box changes. Could someone give me a hand? I'm completely new to ASP.NET, so all I have to work with is my knowledge of C#. :(

Hey,
you can do this with code behind c# code. Just query the database, fetch string from it and bind it to the label's text field.. Like this:

protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
    {
        SqlConnection conn = new SqlConnection(YOURCONNECTIONSTRING);
        conn.Open();
        string query = "SOME QUERY HERE";
        SqlCommand cmd = new SqlCommand(query, conn);

        Label1.Text = cmd.ExecuteScalar().ToString();
        conn.Close();
    }
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.