Re: multiple dropdown lists = multiple data readers???

Tech-Archive recommends: Fix windows errors by optimizing your registry

From: Rick Spiewak (rickspiewak_at_mindspring.com)
Date: 04/22/04


Date: Thu, 22 Apr 2004 00:50:04 -0400

Read the data once, into an array or arraylist, and bind all the
dropdownlists to that.

"Andrew Kidd" <andrew@nospamtoday.com> wrote in message
news:%23xTEGcyJEHA.556@tk2msftngp13.phx.gbl...
> Hi,
>
> I've have a form for the user to fill in which comprises of 5 date ranges,
> each made up of a "FROM" & "TO" date, which is built from a "[Month]"
> dropdownlist & a "[Day]" dropdownlist, as follows:
>
> Period 1 = FROM [Month][day] TO [Month][Day]
> Period 2 = FROM [Month][day] TO [Month][Day]
> Period 3 = FROM [Month][day] TO [Month][Day]
> Period 4 = FROM [Month][day] TO [Month][Day]
> Period 5 = FROM [Month][day] TO [Month][Day]
>
> Ordinarily I use the following code to bind up a dropdownlist:
>
> If IsPostBack = False Then
> Dim objCn As New Odbc.OdbcConnection("DSN=IRS")
> Dim objCmd As New Odbc.OdbcCommand("SELECT DISTINCT
> tblHoliday.Country FROM tblHoliday", objCn)
> Dim objDr As Odbc.OdbcDataReader
>
> objCn.Open()
> objDr = objCmd.ExecuteReader
>
> Me.cboCountries.DataSource = objDr
>
> Me.cboCountries.DataTextField = "Country"
> Me.cboCountries.DataValueField = "Country"
> Me.cboCountries.DataBind()
> objDr.Close()
> objCn.Close()
>
> End If
>
> I've got the months and days each in a separate lookup table, but I'm
faced
> with the prospect of having to run the above routine 10 times each for
both
> the days and months in order to populate the combos.
>
> Is there an easier way to do this?
>
> Thanks in advance
>
> Andy
>
>
>



Relevant Pages

  • RE: Failed to load viewstate
    ... I used a SqlDataSource control to bind the three dropdownlists on ... protected void SearchButton_Click ... you can also post the test custom class(which used to bind ... This posting is provided "AS IS" with no warranties, and confers no rights. ...
    (microsoft.public.dotnet.framework.aspnet.webcontrols)
  • Re: multiple dropdown lists = multiple data readers???
    ... > Read the data once, into an array or arraylist, and bind all the ... > dropdownlists to that. ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: DropDownLists and NULL values
    ... If my database doesn't actually like a zero, in my businesslayer, I will ... > leaving it NULL but this leads to problems with DropDownLists because ... > there is no value to bind to and an eror is raised. ... > obviously not got the 0 value insertion code in the right place. ...
    (microsoft.public.dotnet.framework.aspnet)
  • DropDownLists and NULL values
    ... If a database lookup value is optional I would normally consider ... leaving it NULL but this leads to problems with DropDownLists because ... there is no value to bind to and an eror is raised. ... obviously not got the 0 value insertion code in the right place. ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: dropdownlist.selectedItem not working from in a datalist
    ... But if your dropdownlists doesn't change row by row, ... and only bind them in itemcreate event. ... > oledbcommand object and use it to bind stuff to the dropdownlist. ...
    (microsoft.public.dotnet.framework.aspnet)