0

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#. :(

2
Contributors
1
Reply
2
Views
7 Years
Discussion Span
Last Post by ozgkrc
0

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();
    }
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.