Click here to Skip to main content
15,439,117 members
Please Sign up or sign in to vote.
3.00/5 (1 vote)
See more:
Hello experts

Can anyone help me on how to access data from dynamically added textbox in a Gridview. Findcontrol method wont work here, as the Gridview control lost its childcontrol(template field,textbox etc.) on postback of page.
I know that we need to re-create them on postback but the issue is how to get the data in textbox entered by the user.

I know that one way is to get them from Request.Form string but that is not an acceptable way to deal with it.

Please provide your valuable suggestion on this.

Thanks in advance!







Thank u so much for ur reply Sandeep , But i tried already ur suggetions before , they are not working. Can u please provide me some code sample where with ViewState enabled and recreation of grid u get the data of dynamically added textbox back.

Thanks
Posted
Updated 22-Jun-10 18:31pm
v3

1 solution

dipika29 wrote:
I know that we need to re-create them on postback but the issue is how to get the data in textbox entered by the user


Yes, just re-create the grid and controls and then based on the row selected, find the textbox, you should be able to get the data. Make sure the ViewState of the textbox is enabled.

Further, if you still face issues then you can always use JavaScript to hold on the values for you. Like, one of the ways can be:
1. While creating the textbox dynamically, append a JavaScript function to it on it's onchange/onblurr/onfocusout event. Lets say the function name is DataChanged();

2. Now, whenever textbox data is changed, this JS will be called and in this JS function you can store the textbox value in a Hidden field (hdF1). Also store the grid row index or row identifier in another hidden field (hdF2)

3. After the page postbacks and you have re-created the grid. Use the hdF2 to get to the row and then hdF1 to set back the value of the textbox.

Further, make sure if there were any server events of the dynamically created control then on postback you re-bind the events. Once done, they will be called and executed.
 
Share this answer
 
Comments
dipika29 23-Jun-10 0:24am     CRLF
Thank u for ur reply Sandeep , But i tried already ur suggetions before , they are not working. Can u please provide me some code sample where with ViewState enabled and recreation of grid u get the data of dynamically added textbox back Thanks

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900