|
-
Jul 12th, 2005, 09:45 AM
#1
Thread Starter
New Member
[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)
-
Jul 12th, 2005, 12:47 PM
#2
Junior Member
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)
-
Jul 13th, 2005, 05:58 AM
#3
Thread Starter
New Member
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!
-
Jul 13th, 2005, 06:11 AM
#4
Frenzied Member
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!
-
Jul 13th, 2005, 06:52 AM
#5
Thread Starter
New Member
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?!
-
Jul 13th, 2005, 10:15 AM
#6
Thread Starter
New Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|