Results 1 to 6 of 6

Thread: [RESOLVED] Textbox in datagrid not returning values

  1. #1

    Thread Starter
    New Member
    Join Date
    May 2005
    Posts
    5

    Resolved [RESOLVED] Textbox in datagrid not returning values

    When in edit mode my datagrid displays textboxes in several columns of the editable row. In my update command procedure the text property of the textboxes all appear as "" even though data has been entered. Please could anyone suggest what is causing this. I don't believe that this is an issue with how I reference the text box because doing a watch on e.Item.Cells shows the value in all the textboxes as "", and I have succesfully used datagrids before however below is a code snippet just in case I'm losing the plot....

    Code snippet:
    Private Sub dtgDataEntry_UpdateCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataGridCommandEventArgs) Handles dtgDataEntry.UpdateCommand
    Dim txtWork As New System.Web.UI.WebControls.TextBox

    txtWork = CType(e.Item.Cells(1).Controls(1), TextBox)

  2. #2
    Junior Member
    Join Date
    Jun 2002
    Location
    Midwest
    Posts
    27

    Re: Textbox in datagrid not returning values

    i believe that controls collection is zero-based, so you need to reference controls(0), not controls(1)

  3. #3

    Thread Starter
    New Member
    Join Date
    May 2005
    Posts
    5

    Re: Textbox in datagrid not returning values

    Collections are zero-based, but I need to reference the second control. Thanks for replying, but I'm still stuck!

  4. #4
    Frenzied Member dj4uk's Avatar
    Join Date
    Aug 2002
    Location
    Birmingham, UK Lobotomies: 3
    Posts
    1,131

    Re: Textbox in datagrid not returning values

    Try using the following instead:
    Code:
    txtWork = CType(e.Item.FindControl("TextBox1"), TextBox)
    Where TextBox1 is the id of the textbox you are trying to find.

    DJ

    If I have been helpful please rate my post. If I haven't tell me!

  5. #5

    Thread Starter
    New Member
    Join Date
    May 2005
    Posts
    5

    Re: Textbox in datagrid not returning values

    Thanks for your reply, but it's not a problem with finding the control - the problem is that the text property of the control is apparently set to an empty string ("") when the controlhas had values entered by the user on the web page.

    The textbox is part of an EditItemTemplate of a DataGrid so I dont' see how the HTML and ASP can have become separated. Can anyone explain what has happened?!

  6. #6

    Thread Starter
    New Member
    Join Date
    May 2005
    Posts
    5

    Re: Textbox in datagrid not returning values

    For anyone that's interested the problem was that the datagrid was being rebound before the Update Command code was being called (i.e. in the Page Load event), and thus the new data was being overwritten before my code could get to it.

    To give credit where credit is due, here's where I found the solution:

    http://forums.devx.com/showthread.php?t=142907

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width