i have a drop down list fill using the following code:
If IsPostBack Then
'Put user code to initialize the page here
' create a sqlconnection
Dim cnn As SqlConnection = New SqlConnection("Data
Source=localhost;Initial catalog=Northwind;" & _
"Integrated Security=SSPI")
'create a sql command
Dim cmd As SqlCommand = cnn.CreateCommand
cmd.CommandType = Data.CommandType.Text
cmd.CommandText = "SELECT * FROM Suppliers"
' Set up the DataAdapter and fill the dataset
Dim da As SqlDataAdapter = New SqlDataAdapter
da.SelectCommand = cmd
Dim ds As Suppliers = New Suppliers
da.Fill(ds, "Suppliers")
Dim suppROW As Suppliers.SuppliersRow
For Each suppROW In ds.Suppliers
Me.ddlData.Items.Add(suppROW.SupplierID & suppROW.CompanyName)
Next
i want to set the text of the drop down to companyname
and the value to the supplierID. What am i missing?
thanks
kesHi Kes,
You need to bind the dataset to the dropdown.
Replace this:
> da.Fill(ds, "Suppliers")
> Dim suppROW As Suppliers.SuppliersRow
> For Each suppROW In ds.Suppliers
> Me.ddlData.Items.Add(suppROW.SupplierID &
suppROW.CompanyName)
> Next
With this:
da.Fill(ds, "Suppliers")
ddlData.DataTextField = "CompanyName"
ddlData.DataValueField = "SupplierID"
ddlData.DataSource = dsSuppliers
ddlData.DataBind()
I'm assuming that your Suppliers object is derived from Dataset in the
example above. Good luck! Ken.
Ken Dopierala Jr.
For great ASP.Net web hosting try:
http://www.webhost4life.com/default.asp?refid=Spinlight
If you sign up under me and need help, email me.
"WebBuilder451" <WebBuilder451@.discussions.microsoft.com> wrote in message
news:AB8DDAD7-DBE8-4093-BD3D-C91677304F3F@.microsoft.com...
> i have a drop down list fill using the following code:
> If IsPostBack Then
> 'Put user code to initialize the page here
> ' create a sqlconnection
> Dim cnn As SqlConnection = New SqlConnection("Data
> Source=localhost;Initial catalog=Northwind;" & _
> "Integrated Security=SSPI")
> 'create a sql command
> Dim cmd As SqlCommand = cnn.CreateCommand
> cmd.CommandType = Data.CommandType.Text
> cmd.CommandText = "SELECT * FROM Suppliers"
> ' Set up the DataAdapter and fill the dataset
> Dim da As SqlDataAdapter = New SqlDataAdapter
> da.SelectCommand = cmd
> Dim ds As Suppliers = New Suppliers
> da.Fill(ds, "Suppliers")
> Dim suppROW As Suppliers.SuppliersRow
> For Each suppROW In ds.Suppliers
> Me.ddlData.Items.Add(suppROW.SupplierID &
suppROW.CompanyName)
> Next
> i want to set the text of the drop down to companyname
> and the value to the supplierID. What am i missing?
> thanks
> kes
and I knew that!!
I'm working through a book and i got brain lock on this
thanks
kes
"Ken Dopierala Jr." wrote:
> Hi Kes,
> You need to bind the dataset to the dropdown.
> Replace this:
>
> suppROW.CompanyName)
> With this:
> da.Fill(ds, "Suppliers")
> ddlData.DataTextField = "CompanyName"
> ddlData.DataValueField = "SupplierID"
> ddlData.DataSource = dsSuppliers
> ddlData.DataBind()
> I'm assuming that your Suppliers object is derived from Dataset in the
> example above. Good luck! Ken.
> --
> Ken Dopierala Jr.
> For great ASP.Net web hosting try:
> http://www.webhost4life.com/default.asp?refid=Spinlight
> If you sign up under me and need help, email me.
> "WebBuilder451" <WebBuilder451@.discussions.microsoft.com> wrote in message
> news:AB8DDAD7-DBE8-4093-BD3D-C91677304F3F@.microsoft.com...
> suppROW.CompanyName)
>
>
Subscribe to:
Post Comments (Atom)
0 comments:
Post a Comment