can you bind to a drop down list

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi kind of new to asp.net, I need to have a dropdown list of some type in a webform that shows values from a column
in a table from an SQL server database. I was just wondering if you can do this with a dropdown list, if so how
I have already set up an sql connection, data adapter and dataset as well as binding the data to a datagrid
Thanks
 
Set the datasource to the DataTable. Set the DataTextField to the column
name that you want values to appear in the list box. Set the DataValueField
to the column that you want the actual value to be equal to..may be the same
as dataTextField.

Call DataBind()
Paul said:
Hi kind of new to asp.net, I need to have a dropdown list of some type in
a webform that shows values from a column
in a table from an SQL server database. I was just wondering if you can
do this with a dropdown list, if so how?
I have already set up an sql connection, data adapter and dataset as well
as binding the data to a datagrid.
 
Hi thanks for the response. I was able to get it to work for a listbox.
I set the data value field property to the primary key field in my table. The only problem i
that in the selectedindexchanged event I put a break point and expected to read the primary key valu
into the tempchar, but instead get nothing. Do I need to set up a session state

Private Sub Ls_box_test_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Ls_box_test.SelectedIndexChange
Dim tempint As Intege
Dim tempchar As Cha
tempchar = Ls_box_test.SelectedValue() 'may have to use session state to keep valu
End Su
Thanks again, Paul.
 
You shouldn't have to do that. In the debugger, what value does
SelectedValue evaluate to? can you see the SelectedIndex?
Paul said:
Hi thanks for the response. I was able to get it to work for a listbox.
I set the data value field property to the primary key field in my table. The only problem is
that in the selectedindexchanged event I put a break point and expected to read the primary key value
into the tempchar, but instead get nothing. Do I need to set up a session state?

Private Sub Ls_box_test_SelectedIndexChanged(ByVal sender As
System.Object, ByVal e As System.EventArgs) Handles
Ls_box_test.SelectedIndexChanged
 
Back
Top