M
mykidisgollum
Greetings all,
I'm in a bind this time - I've got a beutifully created and
working(mostly) editable datagrid, all created in code behind - which
works really well for my application.
The only issue preventing me from moving on is I can't pick up the
values in my updatecommand sub - the ones I've just edited.
So I click my editcommand -> pops open editable items -> I make
changes to the text of a textbox for instance -> I click update - > my
updatecommand sub can't pick up the value of the textbox I've just
edited.
I've tried multiple combinations of e.item.cells(i).text, and also
dabbled with the findcontrol method to try to pick up the id of the
template column. I just don't think it's there though - I think it
might not exist because on the next page run, I'm going to have to
rebuild the grid from cache.
I've seen some intrigueing posts about picking up stuff in the page
init but I don't know much about that - anyone who knows, please chime
in.
To maintain the grid, I have it being alternately built or cached as
in this code from my page load:
If Not Page.IsPostBack Then
Else
'If Cache(Session.SessionID & "DataGrid1") = Nothing Then
If Cache(Session.SessionID & "DataGrid1") Is Nothing Then
CreateGrid()
Else
Dim datagrid As DataGrid
datagrid = Cache(Session.SessionID & "DataGrid1")
TD1.Controls.Add(datagrid)
End If
End If
Everything works great - now its time to udpate the database with the
record in question: FOOBARRR CODE BELOW!!!!!!!!!!!!!!!!!!!!!! how to
get textbox value!!!
Public Sub dg_UpdateCommand(ByVal Source As Object, ByVal E As
DataGridCommandEventArgs)
ReturnOpenConnection()
Dim objCommand As OleDbCommand
Dim strSQL As String
Dim txt As New TextBox
txt = CType(Source.items(E.Item.ItemIndex).findcontrol("txtCat"),
TextBox)
Dim foo As String = txt.Text
Dim tb As TableCell = CType(E.Item.Cells(1), TableCell).Text
For Each tb In Source.tablecells
Next
'Dim foo As DataGrid = CType(Source, DataGrid)
' strSQL = "UPDATE " & ReturnFile(dtFiles,
ddlTable.SelectedItem.Value) & " SET CATEGORY = '" &
E.Item.Controls(1).ID("txtCat") & "' WHERE CODE = " &
E.Item.Cells(0).Text
' objCommand = New OleDbCommand(strSQL, objConnection)
' objCommand.ExecuteNonQuery()
Source.EditItemIndex = -1
LoadTableInfo()
Dim dt As DataTable = New DataTable
dt = Cache(Session.SessionID & "dt")
Source.DataSource = dt
Source.DataBind()
End Sub
I can't pick up the value of my textbox!!!!!! Any ideas?
I'm in a bind this time - I've got a beutifully created and
working(mostly) editable datagrid, all created in code behind - which
works really well for my application.
The only issue preventing me from moving on is I can't pick up the
values in my updatecommand sub - the ones I've just edited.
So I click my editcommand -> pops open editable items -> I make
changes to the text of a textbox for instance -> I click update - > my
updatecommand sub can't pick up the value of the textbox I've just
edited.
I've tried multiple combinations of e.item.cells(i).text, and also
dabbled with the findcontrol method to try to pick up the id of the
template column. I just don't think it's there though - I think it
might not exist because on the next page run, I'm going to have to
rebuild the grid from cache.
I've seen some intrigueing posts about picking up stuff in the page
init but I don't know much about that - anyone who knows, please chime
in.
To maintain the grid, I have it being alternately built or cached as
in this code from my page load:
If Not Page.IsPostBack Then
Else
'If Cache(Session.SessionID & "DataGrid1") = Nothing Then
If Cache(Session.SessionID & "DataGrid1") Is Nothing Then
CreateGrid()
Else
Dim datagrid As DataGrid
datagrid = Cache(Session.SessionID & "DataGrid1")
TD1.Controls.Add(datagrid)
End If
End If
Everything works great - now its time to udpate the database with the
record in question: FOOBARRR CODE BELOW!!!!!!!!!!!!!!!!!!!!!! how to
get textbox value!!!
Public Sub dg_UpdateCommand(ByVal Source As Object, ByVal E As
DataGridCommandEventArgs)
ReturnOpenConnection()
Dim objCommand As OleDbCommand
Dim strSQL As String
Dim txt As New TextBox
txt = CType(Source.items(E.Item.ItemIndex).findcontrol("txtCat"),
TextBox)
Dim foo As String = txt.Text
Dim tb As TableCell = CType(E.Item.Cells(1), TableCell).Text
For Each tb In Source.tablecells
Next
'Dim foo As DataGrid = CType(Source, DataGrid)
' strSQL = "UPDATE " & ReturnFile(dtFiles,
ddlTable.SelectedItem.Value) & " SET CATEGORY = '" &
E.Item.Controls(1).ID("txtCat") & "' WHERE CODE = " &
E.Item.Cells(0).Text
' objCommand = New OleDbCommand(strSQL, objConnection)
' objCommand.ExecuteNonQuery()
Source.EditItemIndex = -1
LoadTableInfo()
Dim dt As DataTable = New DataTable
dt = Cache(Session.SessionID & "dt")
Source.DataSource = dt
Source.DataBind()
End Sub
I can't pick up the value of my textbox!!!!!! Any ideas?