Dropdown List Value

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • John

    Dropdown List Value

    I have two dropdown lists that I have bound to a datatable and set the
    DataTextField and DataValueField for. Both lists show the values I
    expect from the database. However, when I need to access the
    valueField for a dropdown list I always get the first value. Here is
    my code I do on load to bind the dropdowns:

    Try
    'load the Division Dropdown
    dtDiv = objDAL.ExecuteD ataTable("GetDi vision")
    With ddDivision
    .DataSource = dtDiv
    .DataTextField = "DivisionNa me"
    .DataValueField = "DivisionID "
    .DataBind()
    End With
    If dtDiv.Rows.Coun t = 1 Then 'load the dropdown of sites
    automatically otherwise wait for the selection
    objParam.Create Parameter("DivI D",
    dtDiv.Rows(0).I tem(0).ToString , DbType.Int32,
    ParameterDirect ion.Input)
    dtSite = objDAL.ExecuteD ataTable("GetPl ant", objParam)
    With ddPlant
    .DataSource = dtSite
    .DataTextField = "PlantName"
    .DataValueField = "PlantID"
    .DataBind()
    End With
    End If

    Again, this loads just fine. I have a button on the form that does a
    redirect based on the values selected:

    Response.Redire ct("Default.asp x?DivID=" & ddDivision.Sele ctedValue &
    "&PlantID=" & ddPlant.Selecte dValue)

    However the ddPlant.Selecte dValue is always 1 (the first value in the
    list) regardless of which value I select in the dropdown. In the
    SelectedIndexCh anged field of the dropdown I tried to set a session
    variable but this event never fires. Anyone have any idea how to get
    the selected values of dropdown lists?

    Thanks.

    John
  • Patrice

    #2
    Re: Dropdown List Value

    It looks like you are rebinding your data on each postback so items are
    cleared and the selected value is changed. You likely should use a "If Not
    IsPostback" test to bind only if this is not a postback...



    "John" <riley_wright@h otmail.coma écrit dans le message de groupe de
    discussion :
    25cadd16-e2bf-4405-b97d-e17c8b38b354...l egroups.com...
    I have two dropdown lists that I have bound to a datatable and set the
    DataTextField and DataValueField for. Both lists show the values I
    expect from the database. However, when I need to access the
    valueField for a dropdown list I always get the first value. Here is
    my code I do on load to bind the dropdowns:
    >
    Try
    'load the Division Dropdown
    dtDiv = objDAL.ExecuteD ataTable("GetDi vision")
    With ddDivision
    .DataSource = dtDiv
    .DataTextField = "DivisionNa me"
    .DataValueField = "DivisionID "
    .DataBind()
    End With
    If dtDiv.Rows.Coun t = 1 Then 'load the dropdown of sites
    automatically otherwise wait for the selection
    objParam.Create Parameter("DivI D",
    dtDiv.Rows(0).I tem(0).ToString , DbType.Int32,
    ParameterDirect ion.Input)
    dtSite = objDAL.ExecuteD ataTable("GetPl ant", objParam)
    With ddPlant
    .DataSource = dtSite
    .DataTextField = "PlantName"
    .DataValueField = "PlantID"
    .DataBind()
    End With
    End If
    >
    Again, this loads just fine. I have a button on the form that does a
    redirect based on the values selected:
    >
    Response.Redire ct("Default.asp x?DivID=" & ddDivision.Sele ctedValue &
    "&PlantID=" & ddPlant.Selecte dValue)
    >
    However the ddPlant.Selecte dValue is always 1 (the first value in the
    list) regardless of which value I select in the dropdown. In the
    SelectedIndexCh anged field of the dropdown I tried to set a session
    variable but this event never fires. Anyone have any idea how to get
    the selected values of dropdown lists?
    >
    Thanks.
    >
    John

    Comment

    • John

      #3
      Re: Dropdown List Value

      On Oct 13, 9:55 am, "Patrice" <http://www.chez.com/scribe/wrote:
      It looks like you are rebinding your data on each postback so items are
      cleared and the selected value is changed. You likely should use a "If Not
      IsPostback" test to bind only if this is not a postback...
      >
      "John" <riley_wri...@h otmail.coma écrit dans le message de groupe de
      discussion :
      25cadd16-e2bf-4405-b97d-e17c8b38b...@m7 4g2000hsh.googl egroups.com...
      >
      >
      >
      I have two dropdown lists that I have bound to a datatable and set the
      DataTextField and DataValueField for.  Both lists show the values I
      expect from the database.  However, when I need to access the
      valueField for a dropdown list I always get the first value.  Here is
      my code I do on load to bind the dropdowns:
      >
      Try
                 'load the Division Dropdown
                 dtDiv = objDAL.ExecuteD ataTable("GetDi vision")
                 With ddDivision
                     .DataSource = dtDiv
                     .DataTextField = "DivisionNa me"
                     .DataValueField = "DivisionID "
                     .DataBind()
                 End With
                 If dtDiv.Rows.Coun t = 1 Then 'load the dropdown of sites
      automatically otherwise wait for the selection
                     objParam.Create Parameter("DivI D",
      dtDiv.Rows(0).I tem(0).ToString , DbType.Int32,
      ParameterDirect ion.Input)
                     dtSite = objDAL.ExecuteD ataTable("GetPl ant", objParam)
                     With ddPlant
                         .DataSource = dtSite
                         .DataTextField = "PlantName"
                         .DataValueField = "PlantID"
                         .DataBind()
                     End With
                 End If
      >
      Again, this loads just fine.  I have a button on the form that does a
      redirect based on the values selected:
      >
      Response.Redire ct("Default.asp x?DivID=" & ddDivision.Sele ctedValue &
      "&PlantID=" & ddPlant.Selecte dValue)
      >
      However the ddPlant.Selecte dValue is always 1 (the first value in the
      list) regardless of which value I select in the dropdown.  In the
      SelectedIndexCh anged field of the dropdown I tried to set a session
      variable but this event never fires.  Anyone have any idea how to get
      the selected values of dropdown lists?
      >
      Thanks.
      >
      John- Hide quoted text -
      >
      - Show quoted text -
      That did it. Thanks.

      John

      Comment

      • =?Utf-8?B?YnJ1Y2UgYmFya2Vy?=

        #4
        Re: Dropdown List Value

        this requires viewstate be turned on. a better approach is to disable
        viewstate and databind in oninit.

        -- bruce (sqlwork.com)


        "Patrice" wrote:
        It looks like you are rebinding your data on each postback so items are
        cleared and the selected value is changed. You likely should use a "If Not
        IsPostback" test to bind only if this is not a postback...
        >
        >
        >
        "John" <riley_wright@h otmail.coma crit dans le message de groupe de
        discussion :
        25cadd16-e2bf-4405-b97d-e17c8b38b354...l egroups.com...
        I have two dropdown lists that I have bound to a datatable and set the
        DataTextField and DataValueField for. Both lists show the values I
        expect from the database. However, when I need to access the
        valueField for a dropdown list I always get the first value. Here is
        my code I do on load to bind the dropdowns:

        Try
        'load the Division Dropdown
        dtDiv = objDAL.ExecuteD ataTable("GetDi vision")
        With ddDivision
        .DataSource = dtDiv
        .DataTextField = "DivisionNa me"
        .DataValueField = "DivisionID "
        .DataBind()
        End With
        If dtDiv.Rows.Coun t = 1 Then 'load the dropdown of sites
        automatically otherwise wait for the selection
        objParam.Create Parameter("DivI D",
        dtDiv.Rows(0).I tem(0).ToString , DbType.Int32,
        ParameterDirect ion.Input)
        dtSite = objDAL.ExecuteD ataTable("GetPl ant", objParam)
        With ddPlant
        .DataSource = dtSite
        .DataTextField = "PlantName"
        .DataValueField = "PlantID"
        .DataBind()
        End With
        End If

        Again, this loads just fine. I have a button on the form that does a
        redirect based on the values selected:

        Response.Redire ct("Default.asp x?DivID=" & ddDivision.Sele ctedValue &
        "&PlantID=" & ddPlant.Selecte dValue)

        However the ddPlant.Selecte dValue is always 1 (the first value in the
        list) regardless of which value I select in the dropdown. In the
        SelectedIndexCh anged field of the dropdown I tried to set a session
        variable but this event never fires. Anyone have any idea how to get
        the selected values of dropdown lists?

        Thanks.

        John
        >
        >

        Comment

        Working...