Databinding
-
Hi, i'm kinda new to the whole asp.net side of developing. I've created a web page with a combobox and textbox. I have a Database with a table (Postcodes). First of all, how do i populate the combobox with data from this table (column: towns) and, second of all, when i change item, how do i make the textbox display the postcode (a.k.a. zip code) (column: postcode). I am using visual basic as my language in visual studio 2005 with a seperate codepage for my aspx page.
Please check out my articles: The ANZAC's articles
-
Hi, i'm kinda new to the whole asp.net side of developing. I've created a web page with a combobox and textbox. I have a Database with a table (Postcodes). First of all, how do i populate the combobox with data from this table (column: towns) and, second of all, when i change item, how do i make the textbox display the postcode (a.k.a. zip code) (column: postcode). I am using visual basic as my language in visual studio 2005 with a seperate codepage for my aspx page.
Please check out my articles: The ANZAC's articles
The ANZAC wrote:
First of all, how do i populate the combobox with data from this table (column: towns)
In form_load event, `SqlConnection dbConn = new SqlConnection(connectionString); dbConn.Open(); SqlDataAdapter da = new SqlDataAdapter("SELECT town FROM table1", dbConn); DataSet ds = new DataSet(); da.Fill(ds); dbConn.Close(); DropDownList1.DataSource = ds.Tables[0]; DropDownList1.DataTextField = "town"; DropDownList1.DataValueField = "postalcode"; DropDownList1.DataBind();` > The ANZAC wrote: > > second of all, when i change item, how do i make the textbox display the postcode (a.k.a. zip code) (column: postcode). `protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e) { txtPostalCode.Text = DropDownList1.SelectedValue; }` That's all. Hope it helps. Thanks and Regards, Michael Sync ( Blog: [http://michaelsync.net](http://michaelsync.net)) _If you want to thank me for my help, please vote my message by clicking one of numbers beside "Rate this message". Why vote? Plz Read [it](http://www.codeproject.com/info/supporter.asp#supporters) here. Thank you. :)_