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

Discussion in 'MCSD' started by smi59550, Jan 18, 2008.

  1. smi59550

    smi59550

    Joined:
    Jan 18, 2008
    Messages:
    2
    I'm trying to place textboxes in the rows of a datagrid so that the user can edit the values. Using itemdatabound, I’m able to input the textboxes into the datagrid. The problem is when I try to retrieve the data from the textboxes; I’m 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’m 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
    Last edited: Jan 18, 2008
    smi59550, Jan 18, 2008
    #1
    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. smi59550
    Replies:
    0
    Views:
    1,519
    smi59550
    Jan 18, 2008
  2. susan_1516

    validating textbox inside datagrid

    susan_1516, Nov 9, 2008, in forum: Software
    Replies:
    0
    Views:
    1,204
    susan_1516
    Nov 9, 2008
  3. Kagu
    Replies:
    0
    Views:
    1,927
  4. kanchangorak

    Get datagrid textbox value

    kanchangorak, Mar 11, 2009, in forum: Software
    Replies:
    0
    Views:
    2,769
    kanchangorak
    Mar 11, 2009
  5. arecev
    Replies:
    0
    Views:
    1,511
    arecev
    Apr 5, 2009
Loading...

Share This Page