473,320 Members | 1,600 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Dropdown controls

Jon
I am using a dropdown control and populating it from an SQL select, like
below

SQL = "SELECT RegionNumber, Description FROM SalesRegion WHERE DateClosed IS
NULL"
cmd.Connection = dbCon
cmd.CommandType = CommandType.Text
cmd.CommandText = SQL
drTemp = cmd.ExecuteReader(CommandBehavior.SequentialAccess )
While drTemp.Read
Me.ddCust.Items.Add(drTemp.GetString(1))
End While
If Not drTemp.IsClosed Then drTemp.Close()

I really want to do something like this (from VB6)

ddCust.AddItem "BOB"
ddCust.ItemData(0) = 15

I want the Description from the select to be the text in the dropdown, yet I
still need to know what the RegionNumber is. What would be the best
solution to this?

Thanks!

--
********************************
Jon
Nov 18 '05 #1
3 1132
Jon
Of course, you always find it 2 seconds later...for anyone else wondering,
here it is:

SQL = "SELECT Description, RegionNumber FROM SalesRegion WHERE DateClosed IS
NULL"

cmd.Connection = dbCon

cmd.CommandType = CommandType.Text

cmd.CommandText = SQL

drTemp = cmd.ExecuteReader(CommandBehavior.SequentialAccess )

While drTemp.Read

Dim l = New ListItem(drTemp.GetString(0), drTemp.GetInt32(1).ToString)

Me.ddCust.Items.Add(l)

End While

If Not drTemp.IsClosed Then drTemp.Close()

"Jon" <ru******@msn.com> wrote in message
news:10*************@corp.supernews.com...
I am using a dropdown control and populating it from an SQL select, like
below

SQL = "SELECT RegionNumber, Description FROM SalesRegion WHERE DateClosed
IS NULL"
cmd.Connection = dbCon
cmd.CommandType = CommandType.Text
cmd.CommandText = SQL
drTemp = cmd.ExecuteReader(CommandBehavior.SequentialAccess )
While drTemp.Read
Me.ddCust.Items.Add(drTemp.GetString(1))
End While
If Not drTemp.IsClosed Then drTemp.Close()

I really want to do something like this (from VB6)

ddCust.AddItem "BOB"
ddCust.ItemData(0) = 15

I want the Description from the select to be the text in the dropdown, yet
I still need to know what the RegionNumber is. What would be the best
solution to this?

Thanks!

--
********************************
Jon

Nov 18 '05 #2
Just throwing some thoughts out to you.

You can set the DataTextField and DataValueField for your DropDown control
and bind the datasource to your control.

ddlCust.DataTextField = "Description"
ddlCust.DataValueField = "RegionNumber"

(You probably will want to set this on the .aspx side as html style
properties of the control.)

Then you can bind directly to it.

ddlCust.DataSource = cmd.ExecuteReader( CommandBehavior.SequentialAccess OR
CommandBehavior.CloseConnection )
ddlCust.DataBind()

So you code would then look like:

SQL = "SELECT Description, RegionNumber FROM SalesRegion WHERE DateClosed IS
NULL"
cmd.Connection = dbCon
cmd.CommandType = CommandType.Text
cmd.CommandText = SQL
ddlCust.DataSource = cmd.ExecuteReader( CommandBehavior.SequentialAccess OR
CommandBehavior.CloseConnection )
ddlCust.DataBind()
'and then you are done.

I am not sure if I did the bitwise correct. I am a c# guy, but you should
know what I am talking about. You should always use the
CommandBehavior.CloseConnection (unless you have a good reason not to).
When the DataReader is closed (by the DataBind method) it will close out the
connection as well.

HTH,

bill
"Jon" <ru******@msn.com> wrote in message
news:10*************@corp.supernews.com...
Of course, you always find it 2 seconds later...for anyone else wondering,
here it is:

SQL = "SELECT Description, RegionNumber FROM SalesRegion WHERE DateClosed IS NULL"

cmd.Connection = dbCon

cmd.CommandType = CommandType.Text

cmd.CommandText = SQL

drTemp = cmd.ExecuteReader(CommandBehavior.SequentialAccess )

While drTemp.Read

Dim l = New ListItem(drTemp.GetString(0), drTemp.GetInt32(1).ToString)

Me.ddCust.Items.Add(l)

End While

If Not drTemp.IsClosed Then drTemp.Close()

"Jon" <ru******@msn.com> wrote in message
news:10*************@corp.supernews.com...
I am using a dropdown control and populating it from an SQL select, like
below

SQL = "SELECT RegionNumber, Description FROM SalesRegion WHERE DateClosed IS NULL"
cmd.Connection = dbCon
cmd.CommandType = CommandType.Text
cmd.CommandText = SQL
drTemp = cmd.ExecuteReader(CommandBehavior.SequentialAccess )
While drTemp.Read
Me.ddCust.Items.Add(drTemp.GetString(1))
End While
If Not drTemp.IsClosed Then drTemp.Close()

I really want to do something like this (from VB6)

ddCust.AddItem "BOB"
ddCust.ItemData(0) = 15

I want the Description from the select to be the text in the dropdown, yet I still need to know what the RegionNumber is. What would be the best
solution to this?

Thanks!

--
********************************
Jon


Nov 18 '05 #3
Jon
Thanks for the tips.
"William F. Robertson, Jr." <wfrobertson_at_kpmg_dot_com> wrote in message
news:uM****************@TK2MSFTNGP14.phx.gbl...
Just throwing some thoughts out to you.

You can set the DataTextField and DataValueField for your DropDown control
and bind the datasource to your control.

ddlCust.DataTextField = "Description"
ddlCust.DataValueField = "RegionNumber"

(You probably will want to set this on the .aspx side as html style
properties of the control.)

Then you can bind directly to it.

ddlCust.DataSource = cmd.ExecuteReader( CommandBehavior.SequentialAccess
OR
CommandBehavior.CloseConnection )
ddlCust.DataBind()

So you code would then look like:

SQL = "SELECT Description, RegionNumber FROM SalesRegion WHERE DateClosed
IS
NULL"
cmd.Connection = dbCon
cmd.CommandType = CommandType.Text
cmd.CommandText = SQL
ddlCust.DataSource = cmd.ExecuteReader( CommandBehavior.SequentialAccess
OR
CommandBehavior.CloseConnection )
ddlCust.DataBind()
'and then you are done.

I am not sure if I did the bitwise correct. I am a c# guy, but you should
know what I am talking about. You should always use the
CommandBehavior.CloseConnection (unless you have a good reason not to).
When the DataReader is closed (by the DataBind method) it will close out
the
connection as well.

HTH,

bill
"Jon" <ru******@msn.com> wrote in message
news:10*************@corp.supernews.com...
Of course, you always find it 2 seconds later...for anyone else
wondering,
here it is:

SQL = "SELECT Description, RegionNumber FROM SalesRegion WHERE DateClosed

IS
NULL"

cmd.Connection = dbCon

cmd.CommandType = CommandType.Text

cmd.CommandText = SQL

drTemp = cmd.ExecuteReader(CommandBehavior.SequentialAccess )

While drTemp.Read

Dim l = New ListItem(drTemp.GetString(0), drTemp.GetInt32(1).ToString)

Me.ddCust.Items.Add(l)

End While

If Not drTemp.IsClosed Then drTemp.Close()

"Jon" <ru******@msn.com> wrote in message
news:10*************@corp.supernews.com...
>I am using a dropdown control and populating it from an SQL select, like
>below
>
> SQL = "SELECT RegionNumber, Description FROM SalesRegion WHERE DateClosed > IS NULL"
> cmd.Connection = dbCon
> cmd.CommandType = CommandType.Text
> cmd.CommandText = SQL
> drTemp = cmd.ExecuteReader(CommandBehavior.SequentialAccess )
> While drTemp.Read
> Me.ddCust.Items.Add(drTemp.GetString(1))
> End While
> If Not drTemp.IsClosed Then drTemp.Close()
>
> I really want to do something like this (from VB6)
>
> ddCust.AddItem "BOB"
> ddCust.ItemData(0) = 15
>
> I want the Description from the select to be the text in the dropdown, yet > I still need to know what the RegionNumber is. What would be the best
> solution to this?
>
> Thanks!
>
> --
> ********************************
> Jon
>



Nov 18 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: E . | last post by:
I seem to be getting nowhere with this problem here is the situation. I have a webform with a data grid populated with the results of a table that has only 3 fields. Then below that are 1...
1
by: sk | last post by:
I have a situation where the list of tables(database) and the columns for each table must be displayed for selection. for each member(displayed in each row) i have to select a table and a column from...
0
by: Jeff | last post by:
After I bind the repeater control in the form_load event, it builds multiple lines based on the number of rows in the dataset. In the repeater control, I have a textbox and a dropdown list box. ...
8
by: Kris Rockwell | last post by:
Hello, I have done the following to bind data to a DropDown box: 1. Drag SQLServer table onto web form to create data connection and data adapter. 2. Generate dataset by right-clicking on...
1
by: Kate Hudson | last post by:
I'm creating a Web Form that has a lot of controls. The first control is an HTML DropDown that contains IDs populated through an ADODB Recordset object. I would like to dynamically fetch data in...
5
by: jung_h_park | last post by:
From: jung_h_park@yahoo.com Newsgroups: microsoft.public.dotnet.framework.aspnet Subject: Dropdown List not retaining its SelectedValue Date: Mon, 26 Jun 2006 21:02:57 -0700 Hello, My...
0
by: cindy | last post by:
I have a dynamic datagrid. I have custom classes for the controls public class CreateEditItemTemplateDDL : ITemplate { DataTable dtBind; string strddlName; string strSelectedID; string...
0
by: kavitascripts | last post by:
I am creating menu using javascript DOM in my asp.net application.When i am opening menu if it is long and if there is any dropdown in page then menu popup goes behind the dropdown,while in case of...
3
by: =?Utf-8?B?bGpsZXZlbmQy?= | last post by:
I need to show a custom control in the DropDown of a Windows.Forms.ToolStripMenuItem (e.g., similar to the Font Color menu item in Word except that the control is specific to my application). I...
8
by: Wingot | last post by:
Hey, I have a program I am trying to write using Visual C#, SQL Server 2005/2008, and Visual Studio 2008, and one part of it includes a Schema called Client. Inside this schema, three tables...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.