Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problem accessing TableRows from Table control

Status
Not open for further replies.

kpobar

Programmer
Jul 10, 2007
10
US
hello there... wondering if anyone has run into this problem... but as I have articulated the problem for this post, I realized a solution, test it, and it works, so I will post the issue and my solution here.

I have created a Table control with 8 rows at design time. I have a dropdown menu whose SelectedIndexChanged event adds rows to that Table control programmatically. But when I iterate through that Table, I am not able to access the rows (and the TextBox values in each row).

I know that dynamic rows have to be re-constructed on each postback, so to solve my problem, I took the code that dynamically adds the rows to the Table control from the ddlBenefitGroup_SelectedIndexChanged method and created a new AddNewRows method using that code... leaving the ddlBenefitGroup_SelectedIndexChanged method body empty.

Then, in the Page_Load method, I check to see if the page is a postback or not... if it is, I call the AddNewRows method. Since the ddlBenefitGroup_SelectedIndexChanged automatically sets a postback, my if branch in the Page_Load method takes care of business... or any other control that posts back will automatically reconstruct the rows added.

 
this would be alot easier if you posted the code in question.

dynamic controls must be added each time and the should be added in the Page.OnInit event. this way viewstate is properly constructed.

you will probally be better off using a gridview instead of building an asp:Table. load the values into a collection and bind the collection to the gridview.

Jason Meckley
Programmer
Specialty Bakers, Inc.
 
Thanks for the reply... will the GridView accommodate TextBox controls?
 
An addition to the last post... I tried throwing my code into the Page_Init method, but it did not render any new rows. I was assuming that it was too early in the page process to recognize the Table control.
 
kpobar said:
will the GridView accommodate TextBox controls
yes. I would suggest researching what the asp.net controls are capaible of. Not knowing how the controls work put you at a disadvantage for developing your system.

again, if you post the code and a breif summary of the process we can better assist you.

Jason Meckley
Programmer
Specialty Bakers, Inc.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top