Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > General Computer Discussion > General Computer Support > ASP.NET VB Using ItemDataBound to create textbox in datagrid rows.

Reply
Thread Tools

ASP.NET VB Using ItemDataBound to create textbox in datagrid rows.

 
 
smi59550 smi59550 is offline
Junior Member
Join Date: Jan 2008
Posts: 2
 
      01-18-2008
I'm trying to place textboxes in the rows of a datagrid so that the user can edit the values. Using itemdatabound, I知 able to input the textboxes into the datagrid. The problem is when I try to retrieve the data from the textboxes; I知 unable to do so. In fact, after the postback, the textboxes disappear along with the newly edited values. Why and how can I keep this from happening? The Page_Load event is not linked to the datagrid so that's not the reason for losing my textboxes. Below are two code snippets from my app written in VB.NET. I知 using Visual Studio.Net 2003.

Private Sub dgMonthly_ItemDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DataGridItemEventArgs) Handles dgMonthly.ItemDataBound

Dim i As Integer
For i = 0 To e.Item.Cells.Count - 2
If e.Item.Cells(0).Text = "Plan" Or e.Item.Cells(0).Text = "Calculated Plan" Then
Dim editcell As TableCell = e.Item.Cells(i + 1)
Dim tb As New TextBox
tb.ID = "Plan"
tb.Columns = 5
tb.Text = e.Item.Cells(i + 1).Text
editcell.Controls.Add(tb)
End If
Next

End Sub

Private Sub ibtnUpdate_Click(ByVal sender As System.Object, ByVal e As System.Web.UI.ImageClickEventArgs) Handles ibtnUpdate.Click
Dim dgi As DataGridItem
Dim i As Integer

For Each dgi In dgMonthly.Items
For i = 0 To dgi.Cells.Count - 2
If dgi.Cells(0).Text = "Plan" Or dgi.Cells(0).Text = "Calculated Plan" Then
Dim Test As TextBox
Test = CType(dgi.Cells(i + 1).FindControl("Plan"), TextBox)

End If
Next
Next
End Sub
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
ASP.NET VB Using ItemDataBound to create textbox in datagrid rows. smi59550 MCSD 0 01-18-2008 09:27 PM
create textbox at run time and insert data from textbox to database tanmaypatankar ASP .Net 0 12-18-2007 03:47 PM
How can I get textbox created ID in itemdatabound Ather Ali Shaikh ASP .Net Datagrid Control 2 09-06-2004 07:00 AM
DataGrid write to Textbox in ItemDataBound help. Jay ASP .Net Datagrid Control 0 07-29-2004 05:11 PM
Datagrid losing changes made in ItemDataBound Tony Middleton ASP .Net 0 04-22-2004 07:27 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57