Hi, I have been pulling my hair out for the last few hours trying to solve this. I have found that you can get a value for DropDownListSelectValue.changed however i need multiple values.

I have configured my dropdown list to Select Name From Resources, however on the query i have selected everything.
Now when I used the selectedindexchanged I am able to extract the Resource Id and fill a textbox with it.
I need to do the same for another 5 or 6 fields and am not use how i go about this.
If anyone could post a C# guide/code It would be very much appreciated.

Recommended Answers

All 6 Replies

Bind DataTextField, and DataValue Field properties.

protected void Page_Load(object sender, EventArgs e)
    {
        if (IsPostBack == false)
        { 
            .....
            DropDownList1.DataSource = dt;
            DropDownList1.DataTextField = "Name";
            DropDownList1.DataValueField = "ResourceID";
            DropDownList1.DataBind();
        }
    }
  protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
    {
        string qry = "select * from tablename where resourceid='" + DropDownList1.SelectedValue + "'";
        .....
        ....

    }

would that code you have just posted not allow for resoruce id and name though? I need to extract more values and dispaly them also in textboxes

protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
    {
        string qry = "select * from tablename where resourceid='" + DropDownList1.SelectedValue + "'";
        SqlConnenction cn=new Sqlconnection("connection_string");
        SqlCommand cmd=new SqlCommand(qry,cn);
        cn.Open();
        SqlDataReader dr=cmd.ExecuteReader();
         if(dr.Read()) {
            TextBox1.Text=dr[0]; // 1st col
            TextBox2.Text=dr[1]; //2nd col
            ....

        }
        dr.Close();
        cn.Close();
    }

thanks! i have another question which is kind of related now.
Once i have populated these text fields i need to be able to keep their datatypes again. I now have the form populated with the desired values , but the purpose of this was to then allow the user to use some of these values to populate another table. I need to be able to insert the resource id from this table into another to be used as a foreign key, but i am unsure how to gain the value before it is converted to a string.

nevermind i have figured out a way to do it using
Int32.Parse(TextBox1.Text);

However if you do read this thread, I have a nice easy one for you :)

How do I trim a datetime datatype to just display date when converted to string!

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.