468,115 Members | 2,120 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

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

Datalist control is bound by an element of the array ???

Hi all,

Data displayed on the datalist control is bound by the column name of the
dataset like this :

<%# DataBinder.Eval(Container.DataItem, "title")%>

Could I use an element of the array (i.e. index=0) which has the name
"title" in place of it ? For example:

<%# DataBinder.Eval(Container.DataItem, Array(0)) %>

Is there anything wrong with the syntax ? Please give me your advise.

Thanks in advance.

Nov 19 '05 #1
4 1953
Hi bienwell:

The DataItem will be an individual array element, so the syntax you
have here won't work, but ...

You can use code other than DataBinder.Eval in the expressions. See:
http://odetocode.com/Articles/278.aspx

--
Scott
http://www.OdeToCode.com/blogs/scott/

On Fri, 6 May 2005 11:11:14 -0400, "bienwell" <bi******@hotmail.com>
wrote:
Hi all,

Data displayed on the datalist control is bound by the column name of the
dataset like this :

<%# DataBinder.Eval(Container.DataItem, "title")%>

Could I use an element of the array (i.e. index=0) which has the name
"title" in place of it ? For example:

<%# DataBinder.Eval(Container.DataItem, Array(0)) %>

Is there anything wrong with the syntax ? Please give me your advise.

Thanks in advance.


Nov 19 '05 #2
Scott,

After reading the document from the http://odetocode.com/Articles/278.aspx
link, I feel it does not like what I want to express. This document
mentionned about multiple values that we can load into the array "HexValue"
and we can bind data for this array. My question is different : I stored
the column names from the SQL statement into the array "ArrField" : For
example : "select Year, Port, SUM(Trucks) Trucks,
SUM(Empty_Truck_Containers) Empty_Truck_Containers, SUM(Trains) Trains FROM
table1 WHERE Year IN (1996,1997,1998) AND Port= 'AK:Alcan' GROUP BY Year,
Port ORDER BY Port, Year ". With this query, I stored columns "Trucks",
"Empty_Truck_Containers", "Trains" into the array "ArrFields" and refer
them later in data binding. The field names in this array may change depends
on the selection from users. Like this, each column has multiple values in
each Year/Month. In the <itemtemplate>, I will use the For Loop to go
through these fields : The syntax like this :

<tr>
<% Dim i as integer
For i=0 to UBound(ViewState("ArrField")) %>
<td>
<%# DataBinder.Eval(Container.DataItem, Array(i)) %>
</td>
<% Next %>
</tr>

I've got an error : "i is not declared "

I cannot specify the column names in data binding because they are
variables.
Do you have any ideas ? Thanks again.

================================================== ======
"Scott Allen" <sc***@nospam.odetocode.com> wrote in message
news:gj********************************@4ax.com...
Hi bienwell:

The DataItem will be an individual array element, so the syntax you
have here won't work, but ...

You can use code other than DataBinder.Eval in the expressions. See:
http://odetocode.com/Articles/278.aspx

--
Scott
http://www.OdeToCode.com/blogs/scott/

On Fri, 6 May 2005 11:11:14 -0400, "bienwell" <bi******@hotmail.com>
wrote:
Hi all,

Data displayed on the datalist control is bound by the column name of the
dataset like this :

<%# DataBinder.Eval(Container.DataItem, "title")%>

Could I use an element of the array (i.e. index=0) which has the name
"title" in place of it ? For example:

<%# DataBinder.Eval(Container.DataItem, Array(0)) %>

Is there anything wrong with the syntax ? Please give me your advise.

Thanks in advance.

Nov 19 '05 #3

Hi bienwell:

I think I see what you are trying to achieve now.

What the article was trying to express was that you aren't restricted
to just using DataBinder in the data binding expressions. You could
invoke some other method of your class to spit out a string.

I'm not quite sure what you want to do in the code below. Did you want
a cell for each entry in the array? If so, it's probably easier to
nest another control inside the DataList cell - like put a Repeater,
DatList, DataGrid inside the cell.

HTH,

--
Scott
http://www.OdeToCode.com/blogs/scott/

On Fri, 6 May 2005 12:53:56 -0400, "bienwell" <bi******@hotmail.com>
wrote:
Scott,

After reading the document from the http://odetocode.com/Articles/278.aspx
link, I feel it does not like what I want to express. This document
mentionned about multiple values that we can load into the array "HexValue"
and we can bind data for this array. My question is different : I stored
the column names from the SQL statement into the array "ArrField" : For
example : "select Year, Port, SUM(Trucks) Trucks,
SUM(Empty_Truck_Containers) Empty_Truck_Containers, SUM(Trains) Trains FROM
table1 WHERE Year IN (1996,1997,1998) AND Port= 'AK:Alcan' GROUP BY Year,
Port ORDER BY Port, Year ". With this query, I stored columns "Trucks",
"Empty_Truck_Containers", "Trains" into the array "ArrFields" and refer
them later in data binding. The field names in this array may change depends
on the selection from users. Like this, each column has multiple values in
each Year/Month. In the <itemtemplate>, I will use the For Loop to go
through these fields : The syntax like this :

<tr>
<% Dim i as integer
For i=0 to UBound(ViewState("ArrField")) %>
<td>
<%# DataBinder.Eval(Container.DataItem, Array(i)) %>
</td>
<% Next %>
</tr>

I've got an error : "i is not declared "

I cannot specify the column names in data binding because they are
variables.
Do you have any ideas ? Thanks again.

================================================= =======
"Scott Allen" <sc***@nospam.odetocode.com> wrote in message
news:gj********************************@4ax.com.. .
Hi bienwell:

The DataItem will be an individual array element, so the syntax you
have here won't work, but ...

You can use code other than DataBinder.Eval in the expressions. See:
http://odetocode.com/Articles/278.aspx

--
Scott
http://www.OdeToCode.com/blogs/scott/

On Fri, 6 May 2005 11:11:14 -0400, "bienwell" <bi******@hotmail.com>
wrote:
>Hi all,
>
>Data displayed on the datalist control is bound by the column name of the
>dataset like this :
>
><%# DataBinder.Eval(Container.DataItem, "title")%>
>
>Could I use an element of the array (i.e. index=0) which has the name
>"title" in place of it ? For example:
>
><%# DataBinder.Eval(Container.DataItem, Array(0)) %>
>
>Is there anything wrong with the syntax ? Please give me your advise.
>
>Thanks in advance.
>
>


Nov 19 '05 #4
Scott,

What I want to do is to use the array of field names for data binding
instead of specifying the field name:
For Example: Users might select field names "Trains", Trucks" in order to
know the Total of Trains and Trucks from the table. In my table, there are
the fieds : Trucks, Trains, Passengers, Pedestrians .... that have the value
number for Month, Year. I cannot specify the field names in data binding
like this:
<td>
<%# DataBinder.Eval(Container.DataItem, "Trains" %>
</td>
<td>
<%# DataBinder.Eval(Container.DataItem, "Trucks" %>
</td>

because the field names are variables and depend on the selection from users
in the first page. I collected the field names from the selection and saved
into the array
"ArrayField" and do the For Loop for databinding

<%# DataBinder.Eval(Container.DataItem, Array(i)) %>

The problem now is the syntax error. It does not know the field names from
the array and gave me an error of the index in the array "i is not declared
". If I replace <%# DataBinder.Eval(Container.DataItem, Array(i)) %> by
<%# DataBinder.Eval(Container.DataItem, Array(0)) or <%#
DataBinder.Eval(Container.DataItem, Array(1)) or <%#
DataBinder.Eval(Container.DataItem, Array(2)) ... then I didn't get the
error.

I hope you get my idea this time. Sorry for my English that is not good.
Please send me e-mail if you're not clear about it.

Thanks again.
==================================================
"Scott Allen" <sc***@nospam.odetocode.com> wrote in message
news:7v********************************@4ax.com...

Hi bienwell:

I think I see what you are trying to achieve now.

What the article was trying to express was that you aren't restricted
to just using DataBinder in the data binding expressions. You could
invoke some other method of your class to spit out a string.

I'm not quite sure what you want to do in the code below. Did you want
a cell for each entry in the array? If so, it's probably easier to
nest another control inside the DataList cell - like put a Repeater,
DatList, DataGrid inside the cell.

HTH,

--
Scott
http://www.OdeToCode.com/blogs/scott/

On Fri, 6 May 2005 12:53:56 -0400, "bienwell" <bi******@hotmail.com>
wrote:
Scott,

After reading the document from the http://odetocode.com/Articles/278.aspxlink, I feel it does not like what I want to express. This document
mentionned about multiple values that we can load into the array "HexValue"and we can bind data for this array. My question is different : I storedthe column names from the SQL statement into the array "ArrField" : For
example : "select Year, Port, SUM(Trucks) Trucks,
SUM(Empty_Truck_Containers) Empty_Truck_Containers, SUM(Trains) Trains FROMtable1 WHERE Year IN (1996,1997,1998) AND Port= 'AK:Alcan' GROUP BY Year,
Port ORDER BY Port, Year ". With this query, I stored columns "Trucks",
"Empty_Truck_Containers", "Trains" into the array "ArrFields" and refer
them later in data binding. The field names in this array may change dependson the selection from users. Like this, each column has multiple values ineach Year/Month. In the <itemtemplate>, I will use the For Loop to go
through these fields : The syntax like this :

<tr>
<% Dim i as integer
For i=0 to UBound(ViewState("ArrField")) %>
<td>
<%# DataBinder.Eval(Container.DataItem, Array(i)) %>
</td>
<% Next %>
</tr>

I've got an error : "i is not declared "

I cannot specify the column names in data binding because they are
variables.
Do you have any ideas ? Thanks again.

================================================= =======
"Scott Allen" <sc***@nospam.odetocode.com> wrote in message
news:gj********************************@4ax.com.. .
Hi bienwell:

The DataItem will be an individual array element, so the syntax you
have here won't work, but ...

You can use code other than DataBinder.Eval in the expressions. See:
http://odetocode.com/Articles/278.aspx

--
Scott
http://www.OdeToCode.com/blogs/scott/

On Fri, 6 May 2005 11:11:14 -0400, "bienwell" <bi******@hotmail.com>
wrote:

>Hi all,
>
>Data displayed on the datalist control is bound by the column name of the >dataset like this :
>
><%# DataBinder.Eval(Container.DataItem, "title")%>
>
>Could I use an element of the array (i.e. index=0) which has the name
>"title" in place of it ? For example:
>
><%# DataBinder.Eval(Container.DataItem, Array(0)) %>
>
>Is there anything wrong with the syntax ? Please give me your advise. >
>Thanks in advance.
>
>

Nov 19 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by Mike Malter | last post: by
1 post views Thread by Scott Schluer | last post: by
reply views Thread by Charlie | last post: by
2 posts views Thread by Andrew | last post: by
1 post views Thread by studen771 | last post: by
3 posts views Thread by Crazy Cat | last post: by
5 posts views Thread by didacticone | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.