469,329 Members | 1,364 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,329 developers. It's quick & easy.

Data Binding Question

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 %>
Nov 19 '05 #1
3 1819
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.

-Brock
DevelopMentor
http://staff.develop.com/ballen
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 %>


Nov 19 '05 #2
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

"Brock Allen" <ba****@NOSPAMdevelop.com> wrote in message
news:76**********************@msnews.microsoft.com ...
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.

-Brock
DevelopMentor
http://staff.develop.com/ballen
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 %>


Nov 19 '05 #3
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);
}
}
}

-Brock
DevelopMentor
http://staff.develop.com/ballen
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
"Brock Allen" <ba****@NOSPAMdevelop.com> wrote in message
news:76**********************@msnews.microsoft.com ...
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.

-Brock
DevelopMentor
http://staff.develop.com/ballen
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 %>


Nov 19 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by Marcin Floryan | last post: by
16 posts views Thread by D Witherspoon | last post: by
1 post views Thread by Patrick | last post: by
1 post views Thread by matty.hall | last post: by
reply views Thread by popsovy | last post: by
10 posts views Thread by Fares Eidi | last post: by
2 posts views Thread by Matthias | last post: by
19 posts views Thread by Larry Lard | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by suresh191 | last post: by
reply views Thread by Purva khokhar | last post: by
reply views Thread by haryvincent176 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.