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

Discussion in 'ASP .Net' started by bienwell, May 6, 2005.

  1. bienwell

    bienwell Guest

    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.
     
    bienwell, May 6, 2005
    #1
    1. Advertising

  2. bienwell

    Scott Allen Guest

    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" <>
    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.
    >
    >
     
    Scott Allen, May 6, 2005
    #2
    1. Advertising

  3. bienwell

    bienwell Guest

    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" <> wrote in message
    news:...
    > 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" <>
    > 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.
    > >
    > >

    >
     
    bienwell, May 6, 2005
    #3
  4. bienwell

    Scott Allen Guest

    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" <>
    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" <> wrote in message
    >news:...
    >> 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" <>
    >> 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.
    >> >
    >> >

    >>

    >
     
    Scott Allen, May 6, 2005
    #4
  5. bienwell

    bienwell Guest

    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" <> wrote in message
    news:...
    >
    > 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" <>
    > 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" <> wrote in message
    > >news:...
    > >> 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" <>
    > >> 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.
    > >> >
    > >> >
    > >>

    > >

    >
     
    bienwell, May 8, 2005
    #5
  6. bienwell

    iatek

    Joined:
    Nov 6, 2007
    Messages:
    1
    Hi,

    I realize that this is an old post, but having run into the same problem, I thought the solutions might be useful to someone else.

    Assuming c# syntax.. this expression would work to display value if the DataItem contains an array. In my case, it is a string array. This would display the 1st element in the string array.

    <%# ((String[])Container.DataItem)[0] %>

    Carol Skelly
    Iatek
     
    iatek, Nov 6, 2007
    #6
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Nevyn Twyll
    Replies:
    8
    Views:
    1,881
  2. sunil panda

    Lower bound & Upper bound

    sunil panda, Dec 25, 2003, in forum: Java
    Replies:
    9
    Views:
    7,252
    thushara wijeratna
    Oct 7, 2008
  3. Rhiner Dan
    Replies:
    1
    Views:
    748
    Mike Wahler
    Mar 27, 2005
  4. Mario Krsnic
    Replies:
    0
    Views:
    382
    Mario Krsnic
    Jun 23, 2006
  5. =?Utf-8?B?QVNQIERldmVsb3Blcg==?=

    How do you bind a datalist that is inside a bound datalist

    =?Utf-8?B?QVNQIERldmVsb3Blcg==?=, Sep 25, 2006, in forum: ASP .Net
    Replies:
    2
    Views:
    580
    =?Utf-8?B?QVNQIERldmVsb3Blcg==?=
    Sep 26, 2006
Loading...

Share This Page