0

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.

2
Contributors
6
Replies
11
Views
8 Years
Discussion Span
Last Post by .netidiot
0

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 + "'";
        .....
        ....

    }
0

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

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

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.

0

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

0

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!

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.