Populating DropDowns

Discussion in 'ASP .Net' started by sck10, Nov 2, 2004.

  1. sck10

    sck10 Guest

    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
     
    sck10, Nov 2, 2004
    #1
    1. Advertising

  2. sck10

    gh0st54 Guest

    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" <> wrote in message
    news:...
    > 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
    >
    >
     
    gh0st54, Nov 2, 2004
    #2
    1. Advertising

  3. sck10

    Saravana Guest

    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" <> wrote in message
    news:...
    > 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
    >
    >
     
    Saravana, Nov 3, 2004
    #3
  4. 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.)
     
    Steven Cheng[MSFT], Nov 4, 2004
    #4
  5. 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.)
     
    Steven Cheng[MSFT], Nov 15, 2004
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. KathyB
    Replies:
    6
    Views:
    577
    Todd Thompson
    Jun 27, 2003
  2. =?Utf-8?B?QW5keQ==?=

    Populating multiple dropdowns

    =?Utf-8?B?QW5keQ==?=, Apr 21, 2005, in forum: ASP .Net
    Replies:
    1
    Views:
    440
    Brock Allen
    Apr 21, 2005
  3. Paul D. Fox

    Help, Populating dropdowns via subroutine

    Paul D. Fox, Aug 25, 2005, in forum: ASP .Net
    Replies:
    1
    Views:
    417
    Paul D. Fox
    Aug 25, 2005
  4. Anup
    Replies:
    2
    Views:
    440
  5. Anup

    Populating dropdowns client-side?

    Anup, Jun 20, 2006, in forum: ASP .Net Web Controls
    Replies:
    0
    Views:
    117
Loading...

Share This Page