Dynamic Fields in ASP.NET (VB)

I have a table that I need to populate based off queries from a table on page load.

the ASPX page has the following table layout
<table>
	<tr>
		<td><td>
		<td colspan="4">Year 1</td>
		<td colspan="4">Year 2</td>
		<td colspan="4">Year 3</td>
	</tr>
	<tr>
		<td><td>
		<td>Q1</td>
		<td>Q2</td>
		<td>Q3</td>
		<td>Q4</td>
		<td>Q1</td>
		<td>Q2</td>
		<td>Q3</td>
		<td>Q4</td>
		<td>Q1</td>
		<td>Q2</td>
		<td>Q3</td>
		<td>Q4</td>
	</tr>
	<tr>
		<td>SALES</td>
		<td><asp:Literal ID="Y1Q1" Text="" runat="server" /></td>
		<td><asp:Literal ID="Y1Q2" Text="" runat="server" /></td>
		<td><asp:Literal ID="Y1Q3" Text="" runat="server" /></td>
		<td><asp:Literal ID="Y1Q4" Text="" runat="server" /></td>
		<td><asp:Literal ID="Y2Q1" Text="" runat="server" /></td>
		<td><asp:Literal ID="Y2Q2" Text="" runat="server" /></td>
		<td><asp:Literal ID="Y2Q3" Text="" runat="server" /></td>
		<td><asp:Literal ID="Y2Q4" Text="" runat="server" /></td>
		<td><asp:Literal ID="Y3Q1" Text="" runat="server" /></td>
		<td><asp:Literal ID="Y3Q2" Text="" runat="server" /></td>
		<td><asp:Literal ID="Y3Q3" Text="" runat="server" /></td>
		<td><asp:Literal ID="Y3Q4" Text="" runat="server" /></td>
	</tr>
.................................................

Open in new window

The data is being pulled in the backend for each year/quarter.

In the code behind I have the following :
Do While xYear < 4
	Select Case xYear
		Case Is = 1
			thisYear = FirstYear.ToString
		Case Is = 2
			thisYear = SecondYear.ToString
		Case Is = 3
			thisYear = ThirdYear.ToString
	End Select

	Do While xQuarter < 5
		Select Case xQuarter
			Case Is = 1
				thisQuarter = 1
			Case Is = 2
				thisQuarter = 2
			Case Is = 3
				thisQuarter = 3
			Case Is = 4
				thisQuarter = 4
		End Select
		
		'This does the query to get the data I will be working with.
		myRecords = Library.GetLFNSTATS(thisYear + thisQuarter)

		For Each row As DataRow In myRecords.Rows

			thisField = "Y" & xYear & "Q" & xQuarter
			thisControl = Me.FindControl(thisField)
			thisControl.text = row("ColumnName").ToString.Trim
			
		Next
		xQuarter += 1
	Loop
	xYear += 1
Loop

Open in new window


When the code runs, the control referenced by thisControl comes back with nothing.
ChaseWooferAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Seven priceFull StackCommented:
How are you passing the do while loop to which ID. you have to pass it to the literal ID or to a table ID

<asp:table id="tableID"

how does it know to return?
0
Seven priceFull StackCommented:
another example on the server side
 tableID.Rows.Add(r)
0
ChaseWooferAuthor Commented:
The solution is as follows:

in the code behind make a reference to the Content Placeholder
Dim MainContent As ContentPlaceHolder = CType(Page.Master.FindControl("MainContent"), ContentPlaceHolder)

Open in new window


Then change :
thisField = "Y" & xYear.ToString & "Q" & xQuarter.ToString
thisControl = Me.FindControl(thisField)
thisControl.text = row("ColumnName").ToString.Trim

Open in new window


thisField = "Y" & xYear.ToString & "Q" & xQuarter.ToString
thisControl = CType(MainContent.FindControl(thisField), Literal)
thisControl.Text = row("ColumnName").ToString.Trim

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
ChaseWooferAuthor Commented:
After much playing arround then going out and getting some fresh air, it came to me where I was doing the references for finding the control.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
ASP.NET

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.