-
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
-
gridview name
I know the seudo code I typed and the viewed source show different gridview names, I assure you they match in the code. Just to make sure that is clear.
Thanks
-
of course...
Well I found the solution, the dynamically added textbox doesn't exist really. Only on the client.
So I created a column of textboxes (templatefield) .. then hide the textboxes on the rows where the user doesn't have to enter any values ...
the code finds them just fine using the .FindControl method.
So often, just explaining the issue to someone (or a group of virtual someones) is enough to flick a switch. Even in the denses of darkness. LOL
Thanks for listening.
-
And thank you for coming back and posting your solution.
It could help someone else with the same or similiar problem.
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
|
Development Centers
-- Android Development Center
-- Cloud Development Project Center
-- HTML5 Development Center
-- Windows Mobile Development Center
|