How to get values out of a grid during an add

Discussion in 'ASP .Net Datagrid Control' started by dew, Jan 6, 2006.

  1. dew

    dew Guest

    I have a grid, when the user clicks on an add link (code below), enters values, then clicks Update

    Public Sub AddRecord(ByVal dgrid)

    Dim ds As DataSet
    Dim dt As DataTable
    Dim dr As DataRow
    ds = Session("DS")

    'Copy the structure of the dataset, no data, and add a blank row for data entry
    dt = ds.Tables(0).Clone
    dr = dt.NewRow()
    dt.Rows.Add(dr)

    'Hide the checkmark column; display the edit/update/cancel column
    dg.Columns(0).Visible = False
    dg.Columns(1).Visible = True


    With dgrid
    .EditItemIndex = 0
    .DataSource = dt
    .DataBind()
    End With

    When the user clicks on Update, I have tried the following and there are no values; I got this from Microsofts Code: Getting Cell Values in the Datagrid Web Server Control. I know the event fires because I can step through it. My datagrid is autogenerated, and this is the only difference from grids that do work. Is that the problem? Can we not get values from a grid when using autogenerated columns??


    Thanks for you rhelp.

    Private Sub dg_UpdateCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataGridCommandEventArgs) Handles DataGrid.UpdateCommand

    Dim i As Integer
    Dim s As String
    For i = 0 To dg.Columns.count - 1
    s &= "<BR>" & e.Item.Cells(i).Text.ToString
    Next
    Response.Write(s)



    End Sub
     
    dew, Jan 6, 2006
    #1
    1. Advertising

  2. dew

    Elton Wang Guest

    Following code shows how to get value from a datagrid cell:

    datagrid.Items(row_index).Cells(col_index).Text

    HTH


    "dew" <> wrote in message news:...
    I have a grid, when the user clicks on an add link (code below), enters values, then clicks Update

    Public Sub AddRecord(ByVal dgrid)

    Dim ds As DataSet
    Dim dt As DataTable
    Dim dr As DataRow
    ds = Session("DS")

    'Copy the structure of the dataset, no data, and add a blank row for data entry
    dt = ds.Tables(0).Clone
    dr = dt.NewRow()
    dt.Rows.Add(dr)

    'Hide the checkmark column; display the edit/update/cancel column
    dg.Columns(0).Visible = False
    dg.Columns(1).Visible = True


    With dgrid
    .EditItemIndex = 0
    .DataSource = dt
    .DataBind()
    End With

    When the user clicks on Update, I have tried the following and there are no values; I got this from Microsofts Code: Getting Cell Values in the Datagrid Web Server Control. I know the event fires because I can step through it. My datagrid is autogenerated, and this is the only difference from grids that do work. Is that the problem? Can we not get values from a grid when using autogenerated columns??


    Thanks for you rhelp.

    Private Sub dg_UpdateCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataGridCommandEventArgs) Handles DataGrid.UpdateCommand

    Dim i As Integer
    Dim s As String
    For i = 0 To dg.Columns.count - 1
    s &= "<BR>" & e.Item.Cells(i).Text.ToString
    Next
    Response.Write(s)



    End Sub
     
    Elton Wang, Jan 7, 2006
    #2
    1. Advertising

  3. dew

    et Guest

    that is what I'm doing, and it is returning no values even though I am typing them in.
    "Elton Wang" <> wrote in message news:...
    Following code shows how to get value from a datagrid cell:

    datagrid.Items(row_index).Cells(col_index).Text

    HTH


    "dew" <> wrote in message news:...
    I have a grid, when the user clicks on an add link (code below), enters values, then clicks Update

    Public Sub AddRecord(ByVal dgrid)

    Dim ds As DataSet
    Dim dt As DataTable
    Dim dr As DataRow
    ds = Session("DS")

    'Copy the structure of the dataset, no data, and add a blank row for data entry
    dt = ds.Tables(0).Clone
    dr = dt.NewRow()
    dt.Rows.Add(dr)

    'Hide the checkmark column; display the edit/update/cancel column
    dg.Columns(0).Visible = False
    dg.Columns(1).Visible = True


    With dgrid
    .EditItemIndex = 0
    .DataSource = dt
    .DataBind()
    End With

    When the user clicks on Update, I have tried the following and there are no values; I got this from Microsofts Code: Getting Cell Values in the Datagrid Web Server Control. I know the event fires because I can step through it. My datagrid is autogenerated, and this is the only difference from grids that do work. Is that the problem? Can we not get values from a grid when using autogenerated columns??


    Thanks for you rhelp.

    Private Sub dg_UpdateCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataGridCommandEventArgs) Handles DataGrid.UpdateCommand

    Dim i As Integer
    Dim s As String
    For i = 0 To dg.Columns.count - 1
    s &= "<BR>" & e.Item.Cells(i).Text.ToString
    Next
    Response.Write(s)



    End Sub
     
    et, Jan 8, 2006
    #3
  4. dew

    Elton Wang Guest

    The code is for boundcolumn.

    If it is textbox, there are two ways to get its value:

    1.
    Dim txt As TextBox = CType(datagrid.Items(row_index).FindControl("the_TextBox_ID"), TextBox)
    Dim txtValue = txt.Text

    2. If you don't have ID for the TextBox:
    Dim txt As TextBox = CType(datagrid.Items(row_index).Cells(row_index).Controls(0), TextBox)
    ' sometimes it might be Controls(1)
    Dim txtValue = txt.Text

    HTH
    "et" <> wrote in message news:...
    that is what I'm doing, and it is returning no values even though I am typing them in.
    "Elton Wang" <> wrote in message news:...
    Following code shows how to get value from a datagrid cell:

    datagrid.Items(row_index).Cells(col_index).Text

    HTH


    "dew" <> wrote in message news:...
    I have a grid, when the user clicks on an add link (code below), enters values, then clicks Update

    Public Sub AddRecord(ByVal dgrid)

    Dim ds As DataSet
    Dim dt As DataTable
    Dim dr As DataRow
    ds = Session("DS")

    'Copy the structure of the dataset, no data, and add a blank row for data entry
    dt = ds.Tables(0).Clone
    dr = dt.NewRow()
    dt.Rows.Add(dr)

    'Hide the checkmark column; display the edit/update/cancel column
    dg.Columns(0).Visible = False
    dg.Columns(1).Visible = True


    With dgrid
    .EditItemIndex = 0
    .DataSource = dt
    .DataBind()
    End With

    When the user clicks on Update, I have tried the following and there are no values; I got this from Microsofts Code: Getting Cell Values in the Datagrid Web Server Control. I know the event fires because I can step through it. My datagrid is autogenerated, and this is the only difference from grids that do work. Is that the problem? Can we not get values from a grid when using autogenerated columns??


    Thanks for you rhelp.

    Private Sub dg_UpdateCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataGridCommandEventArgs) Handles DataGrid.UpdateCommand

    Dim i As Integer
    Dim s As String
    For i = 0 To dg.Columns.count - 1
    s &= "<BR>" & e.Item.Cells(i).Text.ToString
    Next
    Response.Write(s)



    End Sub
     
    Elton Wang, Jan 8, 2006
    #4
    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. Craig G
    Replies:
    5
    Views:
    2,923
    Craig G
    Mar 1, 2005
  2. Kat
    Replies:
    0
    Views:
    299
  3. traveller
    Replies:
    0
    Views:
    1,246
    traveller
    Jan 8, 2008
  4. Dmitry Korolyov

    Datagrid not updated during delete, but updated during insert and update

    Dmitry Korolyov, Sep 22, 2003, in forum: ASP .Net Datagrid Control
    Replies:
    0
    Views:
    442
    Dmitry Korolyov
    Sep 22, 2003
  5. Craig G

    how do i get a SQL timestamp into/out of a grid?

    Craig G, Mar 1, 2005, in forum: ASP .Net Datagrid Control
    Replies:
    0
    Views:
    110
    Craig G
    Mar 1, 2005
Loading...

Share This Page