Home All Groups Group Topic Archive Search About

Fill select control from database

Author
9 Dec 2004 8:27 AM
Rajani
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?

Author
16 Dec 2004 4:33 AM
Michelle Hlaing
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.***
--------------------
Show quote
>Thread-Topic: Fill select control from database
>thread-index: AcTdyN0FujNCN2jKTVS6uugqyTQSRQ==
>X-WBNR-Posting-Host: 202.160.9.12
>From: =?Utf-8?B?UmFqYW5p?= <Raj***@discussions.microsoft.com>
>Subject: Fill select control from database
>Date: Thu, 9 Dec 2004 00:27:04 -0800
>Lines: 17
>Message-ID: <C863481B-88E1-4E75-95C6-24FEF33F6***@microsoft.com>
>MIME-Version: 1.0
>Content-Type: text/plain;
>    charset="Utf-8"
>Content-Transfer-Encoding: 7bit
>X-Newsreader: Microsoft CDO for Windows 2000
>Content-Class: urn:content-classes:message
>Importance: normal
>Priority: normal
>X-MimeOLE: Produced By Microsoft MimeOLE V6.00.3790.0
>Newsgroups: microsoft.public.dotnet.framework.adonet
>NNTP-Posting-Host: TK2MSFTNGXA03.phx.gbl 10.40.1.29
>Path: cpmsftngxa10.phx.gbl!TK2MSFTFEED01.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTNGXA03.phx.gbl
>Xref: cpmsftngxa10.phx.gbl microsoft.public.dotnet.framework.adonet:96676
>X-Tomcat-NG: microsoft.public.dotnet.framework.adonet
>
>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?
>

AddThis Social Bookmark Button