B
Braden
I am having some trouble working through the logic of binding a dropdown list to a database here is my code. Please note that this works fine if I use a dropdown list that I add the values to manually
I have tried to capture the selected item in the button command, I have tried it with and without binding the data after the post, but nothing seems to return the selected item. I am user I am doing something wrong with the post but what. Once again if I create the options manually this works fine
Thanks in advance for any help
//Example --
private void Page_Load(object sender, System.EventArgs e
TextBox1.Text = ListBox1.SelectedValue.ToString()
if(!Page.IsPostBack
GetProducts(SelectedProduct)
private void GetProducts(int ProductSelected
string getProducts = "select ProductNumber, iResolutionGroup from sometable"
System.Data.SqlClient.SqlConnection sqlCon2 = new System.Data.SqlClient.SqlConnection("server=server;uid=sa;pwd=password;database=db")
System.Data.SqlClient.SqlCommand sqlComm = new System.Data.SqlClient.SqlCommand(getProducts,sqlCon2)
System.Data.SqlClient.SqlDataAdapter sqlDA = new System.Data.SqlClient.SqlDataAdapter()
sqlDA.SelectCommand = sqlComm
DataSet Products_ds = new DataSet()
sqlDA.Fill(Products_ds)
sqlCon2.Close()
//Products_dd is the DropDown list
Products_dd.DataSource = Products_ds
Products_dd.DataTextField = "ProductNumber"
Products_dd.DataValueField = "iResolutionGroup"
Products_dd.DataBind()
private void Button1_Click(object sender, System.EventArgs e
//Do something, but more importantly create the post
I have tried to capture the selected item in the button command, I have tried it with and without binding the data after the post, but nothing seems to return the selected item. I am user I am doing something wrong with the post but what. Once again if I create the options manually this works fine
Thanks in advance for any help
//Example --
private void Page_Load(object sender, System.EventArgs e
TextBox1.Text = ListBox1.SelectedValue.ToString()
if(!Page.IsPostBack
GetProducts(SelectedProduct)
private void GetProducts(int ProductSelected
string getProducts = "select ProductNumber, iResolutionGroup from sometable"
System.Data.SqlClient.SqlConnection sqlCon2 = new System.Data.SqlClient.SqlConnection("server=server;uid=sa;pwd=password;database=db")
System.Data.SqlClient.SqlCommand sqlComm = new System.Data.SqlClient.SqlCommand(getProducts,sqlCon2)
System.Data.SqlClient.SqlDataAdapter sqlDA = new System.Data.SqlClient.SqlDataAdapter()
sqlDA.SelectCommand = sqlComm
DataSet Products_ds = new DataSet()
sqlDA.Fill(Products_ds)
sqlCon2.Close()
//Products_dd is the DropDown list
Products_dd.DataSource = Products_ds
Products_dd.DataTextField = "ProductNumber"
Products_dd.DataValueField = "iResolutionGroup"
Products_dd.DataBind()
private void Button1_Click(object sender, System.EventArgs e
//Do something, but more importantly create the post