DropDownList in GridView column no declared in Button_Click

Discussion in 'ASP .Net Web Controls' started by James, Apr 1, 2008.

  1. James

    James Guest

    I have a GridView where I have added a DropDownList control that is bound to
    a field in the GridView.

    I want to be able to set the dropdown for each row in the gridview then
    update the rows on the submit (button_click).

    I have the following code for the button_click. The problem I'm having is
    that "DropDownListSeries" is not declared. I need to know how to use that in
    the button_click function.

    Any help would be GREATLY appreciated!

    Imports System.Data.SqlClient

    Partial Class members_members_lineups

    Inherits System.Web.UI.Page





    Protected Sub ButtonSubmit_Click(ByVal sender As Object, ByVal e As
    System.EventArgs) Handles ButtonSubmit.Click

    Dim driverID As Integer

    Dim teamID As Integer

    Dim Series As String



    Dim row As GridViewRow

    For Each row In GridViewLineup.Rows

    driverID = row.Cells(4).Text

    teamID = row.Cells(5).Text

    Series = DropDownListSeries.SelectedValue

    Dim sql = "UPDATE tblRosters SET series='" & Series & "' WHERE driverID=" &
    driverID

    SqlDataSource_Rosters.UpdateCommand = sql

    SqlDataSource_Rosters.Update()

    Next

    GridViewLineup.DataBind()

    End Sub



    End Class
     
    James, Apr 1, 2008
    #1
    1. Advertising

  2. James

    James Guest

    I figured it out:

    Dim ddl As DropDownList
    ddl = row.FindControl("DropDownList_Series")
    series = ddl.SelectedValue


    "James" <> wrote in message
    news:...
    >I have a GridView where I have added a DropDownList control that is bound
    >to a field in the GridView.
    >
    > I want to be able to set the dropdown for each row in the gridview then
    > update the rows on the submit (button_click).
    >
    > I have the following code for the button_click. The problem I'm having is
    > that "DropDownListSeries" is not declared. I need to know how to use that
    > in the button_click function.
    >
    > Any help would be GREATLY appreciated!
    >
    > Imports System.Data.SqlClient
    >
    > Partial Class members_members_lineups
    >
    > Inherits System.Web.UI.Page
    >
    >
    >
    >
    >
    > Protected Sub ButtonSubmit_Click(ByVal sender As Object, ByVal e As
    > System.EventArgs) Handles ButtonSubmit.Click
    >
    > Dim driverID As Integer
    >
    > Dim teamID As Integer
    >
    > Dim Series As String
    >
    >
    >
    > Dim row As GridViewRow
    >
    > For Each row In GridViewLineup.Rows
    >
    > driverID = row.Cells(4).Text
    >
    > teamID = row.Cells(5).Text
    >
    > Series = DropDownListSeries.SelectedValue
    >
    > Dim sql = "UPDATE tblRosters SET series='" & Series & "' WHERE driverID="
    > & driverID
    >
    > SqlDataSource_Rosters.UpdateCommand = sql
    >
    > SqlDataSource_Rosters.Update()
    >
    > Next
    >
    > GridViewLineup.DataBind()
    >
    > End Sub
    >
    >
    >
    > End Class
    >
    >
     
    James, Apr 2, 2008
    #2
    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. Paul Aspinall
    Replies:
    1
    Views:
    422
    Duray AKAR
    Aug 12, 2003
  2. Kenneth

    Button_Click change

    Kenneth, Aug 22, 2003, in forum: ASP .Net
    Replies:
    4
    Views:
    474
    Kevin Spencer
    Aug 22, 2003
  3. Tim Thomas
    Replies:
    3
    Views:
    839
  4. JohnZing

    declared or not declared ?

    JohnZing, Feb 5, 2006, in forum: ASP .Net
    Replies:
    3
    Views:
    1,624
    Jon Paal
    Feb 5, 2006
  5. Keith G Hicks
    Replies:
    3
    Views:
    810
    Keith G Hicks
    Feb 18, 2008
Loading...

Share This Page