Link to home
Start Free TrialLog in
Avatar of ChaseWoofer
ChaseWoofer

asked on

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.
Avatar of Seven price
Seven price
Flag of United States of America image

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?
another example on the server side
 tableID.Rows.Add(r)
ASKER CERTIFIED SOLUTION
Avatar of ChaseWoofer
ChaseWoofer

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of ChaseWoofer
ChaseWoofer

ASKER

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.