Fill select control from database

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

Guest

Hello,

I have a table with brand_code and brand_name, 2 columns. brand_code is PK.
I want to retrieve these values from the database and fill to select control.
I tried using datareader.
dr=cmd.exectereader()
while dr.read()
selBrand.attributes.add(dr("brand_code"),dr("brand_name"))
end while

Its storing value and text same with brand_name

I want to store brand_code in value and brand_name visible to user in the
selected control. Coz only brand_code is passed for internal database
transactions.

How do i retrieve the selected brand_code?
 
hi Rajani,

Let say that the control you are using is a DropDownList, ddl.

If you retrieve the data into a dataset, ds, you can do this:

ddl.DataSource = ds;
ddl.DataMember = ds.<tablename>.ToString();
ddl.DataTextField = ds.<tablename>.BrandNameColumn.ColumnName;
ddl.DataValueField = ds.<tablename>.BrandCodeColumn.ColumnName;
ddl.DataBind();

To retrieve the brand code:

ddl.SelectedValue

Hope that helps,

Michelle

***Disclaimer: This posting is provided "as is" with no warranties and confers no rights.***
--------------------
 
Back
Top