Creating Databound DropDown Lists in ASP.NET arti

Visse

New Member
just to help anyone else who like me is new at this....<BR><BR>I was trying out the above article using System.Data.SqlClient instead of oledb but it would not work in the fact the list box contained the string "system.object.datarecord"in both datafields and valuefields or something similar instead of the actual contents of the fieldname. <BR><BR>Found the solution in that before<BR><BR>ListBoxProjects.DataBind()<BR><BR>I had to tell the listbox the datafield and valuefields<BR><BR>ListBoxProjects.DataTextField = "field1"<BR>ListBoxProjects.DataValueField = "field2"<BR><BR>I include the code too <BR><BR>Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load<BR><BR><BR><BR> Dim myConnection As SqlConnection<BR> Dim myCommand As SqlCommand<BR> Dim myDatareader As SqlDataReader<BR><BR> myConnection = New SqlConnection("server=lonsr;database=test;uid=test")<BR> myConnection.Open()<BR><BR><BR><BR><BR> myCommand = New SqlCommand("Select ttmltimelineid,ttmlName from tttmltimeline", myConnection)<BR> myDatareader = myCommand.ExecuteReader()<BR><BR><BR> <BR><BR> ListBoxProjects.DataSource() = myDatareader<BR> ListBoxProjects.DataTextField = "ttmlName"<BR> ListBoxProjects.DataValueField = "ttmltimelineid"<BR> ListBoxProjects.DataBind()<BR><BR> End Sub<BR><BR><BR>any suggestions on how to improve the code greatly recieved <BR>
 
Back
Top