Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Populating DropDowns

Reply
Thread Tools

Populating DropDowns

 
 
sck10
Guest
Posts: n/a
 
      11-02-2004
Hello,

I have two dropdown objects that I want to use the same datasource for each.
I tried the following, but it doesn't populate the second dropdown. Do I
need to close the OleDbDataReader and then re-open it to populate the second
dropdown object?

Thanks in advance,
sck10




'Populate the TerminationType combo box
'--------------------------------------
Dim spTerminationType As OleDb.OleDbDataReader
Dim prmTermType As OleDbParameter
Dim cmdTermType As New OleDb.OleDbCommand("spMySearch", cnnSearch)
cmdTermType.CommandType = CommandType.StoredProcedure

prmTermType = cmdTermType.Parameters.Add("@strParm01", OleDbType.VarChar)
: prmTermType.Value = "FindTerminationType"
prmTermType = cmdTermType.Parameters.Add("@strParm02", OleDbType.VarChar)
: prmTermType.Value = "NoParameter"
prmTermType = cmdTermType.Parameters.Add("@strParm03", OleDbType.VarChar)
: prmTermType.Value = "NoParameter"
prmTermType = cmdTermType.Parameters.Add("@strParm04", OleDbType.VarChar)
: prmTermType.Value = "NoParameter"

spTerminationType = cmdTermType.ExecuteReader()

'TerminationType 1
Me.ddlTerminationType1.DataSource = spTerminationType
Me.ddlTerminationType1.DataTextField = "TerminationType_ID"
Me.ddlTerminationType1.DataBind()

'TerminationType 2
Me.ddlTerminationType2.DataSource = spTerminationType
Me.ddlTerminationType2.DataTextField = "TerminationType_ID"
Me.ddlTerminationType2.DataBind()

spTerminationType.Close() : spTerminationType = Nothing


 
Reply With Quote
 
 
 
 
gh0st54
Guest
Posts: n/a
 
      11-02-2004
my guess would be that once the reader reaches the end you would have to
reset it a the beginning

why don't you use a dataset


"sck10" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Hello,
>
> I have two dropdown objects that I want to use the same datasource for

each.
> I tried the following, but it doesn't populate the second dropdown. Do I
> need to close the OleDbDataReader and then re-open it to populate the

second
> dropdown object?
>
> Thanks in advance,
> sck10
>
>
>
>
> 'Populate the TerminationType combo box
> '--------------------------------------
> Dim spTerminationType As OleDb.OleDbDataReader
> Dim prmTermType As OleDbParameter
> Dim cmdTermType As New OleDb.OleDbCommand("spMySearch", cnnSearch)
> cmdTermType.CommandType = CommandType.StoredProcedure
>
> prmTermType = cmdTermType.Parameters.Add("@strParm01",

OleDbType.VarChar)
> : prmTermType.Value = "FindTerminationType"
> prmTermType = cmdTermType.Parameters.Add("@strParm02",

OleDbType.VarChar)
> : prmTermType.Value = "NoParameter"
> prmTermType = cmdTermType.Parameters.Add("@strParm03",

OleDbType.VarChar)
> : prmTermType.Value = "NoParameter"
> prmTermType = cmdTermType.Parameters.Add("@strParm04",

OleDbType.VarChar)
> : prmTermType.Value = "NoParameter"
>
> spTerminationType = cmdTermType.ExecuteReader()
>
> 'TerminationType 1
> Me.ddlTerminationType1.DataSource = spTerminationType
> Me.ddlTerminationType1.DataTextField = "TerminationType_ID"
> Me.ddlTerminationType1.DataBind()
>
> 'TerminationType 2
> Me.ddlTerminationType2.DataSource = spTerminationType
> Me.ddlTerminationType2.DataTextField = "TerminationType_ID"
> Me.ddlTerminationType2.DataBind()
>
> spTerminationType.Close() : spTerminationType = Nothing
>
>



 
Reply With Quote
 
 
 
 
Saravana
Guest
Posts: n/a
 
      11-03-2004
You cant use datareader for this purpose, you can move it to dataset.
Datareader can accessed for second time once it is open and moved to the
end.

--
Saravana
http://dotnetjunkies.com/WebLog/saravana/
www.ExtremeExperts.com


"sck10" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Hello,
>
> I have two dropdown objects that I want to use the same datasource for

each.
> I tried the following, but it doesn't populate the second dropdown. Do I
> need to close the OleDbDataReader and then re-open it to populate the

second
> dropdown object?
>
> Thanks in advance,
> sck10
>
>
>
>
> 'Populate the TerminationType combo box
> '--------------------------------------
> Dim spTerminationType As OleDb.OleDbDataReader
> Dim prmTermType As OleDbParameter
> Dim cmdTermType As New OleDb.OleDbCommand("spMySearch", cnnSearch)
> cmdTermType.CommandType = CommandType.StoredProcedure
>
> prmTermType = cmdTermType.Parameters.Add("@strParm01",

OleDbType.VarChar)
> : prmTermType.Value = "FindTerminationType"
> prmTermType = cmdTermType.Parameters.Add("@strParm02",

OleDbType.VarChar)
> : prmTermType.Value = "NoParameter"
> prmTermType = cmdTermType.Parameters.Add("@strParm03",

OleDbType.VarChar)
> : prmTermType.Value = "NoParameter"
> prmTermType = cmdTermType.Parameters.Add("@strParm04",

OleDbType.VarChar)
> : prmTermType.Value = "NoParameter"
>
> spTerminationType = cmdTermType.ExecuteReader()
>
> 'TerminationType 1
> Me.ddlTerminationType1.DataSource = spTerminationType
> Me.ddlTerminationType1.DataTextField = "TerminationType_ID"
> Me.ddlTerminationType1.DataBind()
>
> 'TerminationType 2
> Me.ddlTerminationType2.DataSource = spTerminationType
> Me.ddlTerminationType2.DataTextField = "TerminationType_ID"
> Me.ddlTerminationType2.DataBind()
>
> spTerminationType.Close() : spTerminationType = Nothing
>
>



 
Reply With Quote
 
Steven Cheng[MSFT]
Guest
Posts: n/a
 
      11-04-2004
Hi Sck10,

I think Gh0st54's suggestion is reasonable, a DataReader is a forward only
list and after we loop through all the records in it, the "Current"
position is pointed to the end of the records in it so the second time you
bind it to a dropdownlist, there is no data returned.
Alternatively, we can either
1. Close and get a new DataReader again as you said.

2. Or use DataAdapter to get a DataSet (contains DataTable) so that we can
bind DataTable to multi- databinding controls.

If you have anything unclear ,please feel free to post here.
Thanks.


Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

 
Reply With Quote
 
Steven Cheng[MSFT]
Guest
Posts: n/a
 
      11-15-2004
Hi Sck10,

Have you got any further progress or ideas on this issue? If there're
anything else we can help, please feel free to post here. Thanks.

Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Populating dropdowns client-side? Anup ASP .Net 2 06-20-2006 01:44 PM
Populating dropdowns client-side? Anup ASP .Net Web Controls 0 06-20-2006 09:32 AM
Help, Populating dropdowns via subroutine Paul D. Fox ASP .Net 1 08-25-2005 12:47 PM
Populating multiple dropdowns =?Utf-8?B?QW5keQ==?= ASP .Net 1 04-21-2005 09:29 AM
Page Post Back -- how to retain selecteditem.value of TWO dropdowns??? KathyB ASP .Net 6 06-27-2003 03:33 PM



Advertisments