Data Binding Question

B

bbernieb

Hi, All,



Is it possible to access a variable inside of a data binding, without the
variable being out of scope?
(Note: On the DataBinder line, I get an error message that says "Name 'i' is
not declared". The data bind is for a DataList.)







Example:



<%
Dim i As String
For Each i In ViewState("ArrField")
%>
<td><%# DataBinder.Eval(Container.DataItem, i.ToString() %>
</td>
<%Next %>
 
B

Brock Allen

No, the <%%> syntax is put into a Render method, which is a seperate method
from the <%# %> DataBinding code snippet. What exactly are you trying to
do... this looks very ASP-sih. Maybe we can suggest a more ASP.NET appropriate
approach.
 
B

bbernieb

Brock,

I have several nested DataList controls, which are similar to the
Drilldown report that can be found in the Reports Starter Kit. The
difference is that in one of the DataList controls, I would like to
iterate through an array (some collection) to create table definitions
(<td>s) for the DataList. The size and content of the collection is
determined by the user's selections. With the collection I would like
to do two things.

1. Define the header template
2. Bind data to the DataList control inside the item template. The
items inside of the collection are columns in a DataSet. That's
explains (<%#
DataBinder.Eval(Container.DataItem, i.ToString() %>)

The DataGrid control may be more suitable but I would like to drilldown
one more time, as seen below. Note, I would be drilling down into a
DataGrid.


Sometimes it's hard to give up old habits.

bbernienb



Cars Trucks Buses
1990 DATA DATA DATA
1991 DATA DATA DATA
1992 DATA DATA DATA
1993 DATA DATA DATA
1994 DATA DATA DATA
1995 DATA DATA DATA






Cars Trucks Buses
1990 DATA DATA DATA
Jan DATA DATA DATA
Feb DATA DATA DATA
Mar DATA DATA DATA
Apr DATA DATA DATA
May DATA DATA DATA
Jun DATA DATA DATA
Jul DATA DATA DATA
Aug DATA DATA DATA
Sep DATA DATA DATA
Oct DATA DATA DATA
Nov DATA DATA DATA
Dec DATA DATA DATA
1991 DATA DATA DATA
1992 DATA DATA DATA
1993 DATA DATA DATA
1994 DATA DATA DATA
1995 DATA DATA DATA
 
B

Brock Allen

So why don't you just do this all in codebehind and dynamically create a
Table, TableRow and TableCell objects? Pseudocode sample:

void Page_Load(...)
{
if (YourCondition)
{
yourData = GetYourData();
for (int i = 0; i < yourData.Length; i++)
{
TableRow row = new TableRow();
TableCell cell = new TableCell();
cell.Text = i.ToString();
row.Cells.Add(cell);
cell = new TableCell();
cell.Text = yourData.Data;
row.Cells.Add(cell);
YourTableInTheASPX.Rows.Add(row);
}
}
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,226
Members
46,815
Latest member
treekmostly22

Latest Threads

Top