dynamically created datagrid updatecommand not picking up values!!!! about to go crazy!

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?
 
V

vMike

This may help. When you are in edit mode the tablecell for the dategrid have
textbox controls within them. You can access them using something like this
(where the cell number is the column using a 0 base).

(CType(e.Item.Cells(7).Controls(0), TextBox).text

See if that helps
 
D

david fields

Sorry, no dice on the suggestion, but thanks! Specified cast invalid is
the returned error. Anyone know anything baout building a dynamic grid
in teh page init?

David Fields
 

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,754
Messages
2,569,527
Members
44,999
Latest member
MakersCBDGummiesReview

Latest Threads

Top