|
-
Retrieving value from dynamically added textbox in GridView
Hello all
I am hoping someone can help me out with this problem.
I have a gridview control, I have 1 column where I add textboxes where the user can enter data (not the entire column, just a few selected cells). I do this using this code in the RowDataBound event:
If e.Row.RowType = DataControlRowType.DataRow Then
If e.Row.Cells(4).Text = "xxx" Then
' this indicates where a textbox should be placed to allow the user to enter an inv or check #
Dim txtbx As New TextBox
txtbx.Visible = True
txtbx.ID = "txtRow" & e.Row.RowIndex.ToString
txtbx.Width = Unit.Pixel(75)
txtbx.BackColor = Color.LightYellow
e.Row.Cells(4).Controls.Add(txtbx)
txtbx = Nothing
End If
The textboxes are added and I am able to interact with them just fine.
My problem is when I attempt to read the value of the textboxes, I can never find them in the gridview.
I have tried using .. something like
dim txtbox as textbox
for x=0 to gridview.rows.count - 1
txtbox=gridview.rows(x).findcontrol("txtBox" & x.tostring)
next
also tried..
dim txtbox as textbox
for x=0 to gridview.rows.count - 1
txtbox=gridview.rows(x).cells(0).controls.item(0)
next
also used TryCast which always returns nothing as well.
I also just tried using the full name that the gridview gave the textbox, by looking at the source in the browser I saw it had "gridview_ctl3_txtRow1"
So I tried to loop ALL controls in the ME object to find that textbox, again it was not found.
Is it unaccessible because I added it dynamically?
Here is what a record that has been given a textbox looks like in the rendered HTML (via view source)
<td> </td><td>(none selected)</td><td> </td><td align="right">$1,334.95</td><td align="center"><input name="grdExpList:_ctl3:txtRow1" type="text" id="grdExpList__ctl3_txtRow1" style="background-color:LightYellow;width:75px;" /></td>
The control is there, I just can't get to it.
This is a VS2008 asp.net VB project.
Anyone have any ideas? I figure I am missing something simple as most obvious solutions are come to last.
Thanks for any assistance you may lend.
Jon
Similar Threads
-
By timmym in forum ASP.NET
Replies: 8
Last Post: 11-23-2008, 07:31 AM
-
Replies: 1
Last Post: 05-26-2008, 08:22 AM
-
By seanlaw in forum ASP.NET
Replies: 1
Last Post: 02-28-2007, 06:50 PM
-
By Robert in forum ASP.NET
Replies: 4
Last Post: 09-02-2006, 09:18 AM
-
By David Hirschfeld in forum ASP.NET
Replies: 0
Last Post: 01-05-2003, 11:49 AM
Tags for this Thread
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
|
Top DevX Stories
Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL
|
Bookmarks