How to get values out of a grid during an add

D

dew

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
 
E

Elton Wang

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

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

HTH


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
 
E

et

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

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

HTH


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
 
E

Elton Wang

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
that is what I'm doing, and it is returning no values even though I am typing them in.
Following code shows how to get value from a datagrid cell:

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

HTH


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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,049
Latest member
Allen00Reed

Latest Threads

Top