Click here to Skip to main content
14,739,729 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have created a gridview with 2 template fields created at design time. I want to generate more template fields(gridview columns) dynamically at runtime,because no. of columns in the gridview is varying every time.I also need to have a textbox inside every template field.

I have done up till generating these template fields along with the textboxes using ITemplete and I can also get these textboxes at the RowDataBound event. Then I am allowing the user to update the values in the textboxes. But when I try to get these textbox values on click event of the submit button which is outside the gridview, I can't find those newly generated columns and hence neither the textboxes.


Can anyone please help me to find out the solution to this so that I can get the textbox values on submit button's click event.

Thanks.
Posted
Comments
Ankur\m/ 6-Jul-10 7:47am
   
Use 'Add Comment' below User's answer to discuss with user rather than creating new answers.

What you have to do is, you need to recreate the template columns with textboxes again on postback (on click of submit button), then and then only you will get your template column as well as the value of textboxes
   
Comments
Ankur\m/ 6-Jul-10 7:45am
   
[Moved from answer]:
ananda8886 wrote -
Thanks for the reply.
But if I am creating the template fields along with the textbox again, on the postback, how I will get the values entered by the user?Because then the templateFields as well as the textboxes will be the new ones.
It will retain its value due to view-state. Just you need to make sure that the id which you have created for template columns and textboxes at initial page load, should be same after postback.
   
Comments
Ankur\m/ 6-Jul-10 7:46am
   
[Moved from answer]:

anada8886 wrote -
Thanks for the help.

I got the solution. I just had to remove the IsPostback() condition which I was checking on Page Load.
I think in IsPostback(), you had written the code of adding template columns and textboxes in those columns.
   
Comments
Ankur\m/ 6-Jul-10 7:47am
   
[Moved from answer]:
anada8886 wrote -
Yes right. I was adding the Template Fields on page load inside IsPostback.
i think use HTML table at run time.
   

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