Bind ArrayList to DataList

Discussion in 'ASP .Net' started by Bob Lehmann, Nov 5, 2005.

  1. Bob Lehmann

    Bob Lehmann Guest

    Hi,

    I'm trying to bind an ArrayList to a DataList.

    I get the error
    DataBinder.Eval: 'System.String' does not contain a property with the name
    Name.

    I don't know what property of ArrayList I should be using instead of "Name"
    in default.aspx.

    Can someone point me in the right direction?

    default.aspx.vb -
    Dim di As New DirectoryInfo(Current.Server.MapPath("images/position"))
    Dim FileList As FileInfo() = di.GetFiles()
    Dim File As FileInfo
    Dim ary As New ArrayList
    For Each File In FileList
    ary.Add(File.Name)
    Next

    ThumbList.DataSource = ary
    ThumbList.DataBind()

    default.aspx -
    <asp:datalist id="ThumbList"
    repeatdirection="Horizontal"
    repeatcolumns="5"
    gridlines="Both"
    repeatlayout="Table"
    itemstyle-cssclass="thumb"
    runat="server">
    <itemtemplate>
    <img src='images/position/thumb/<%#DataBinder.Eval(Container,
    "DataItem.Name")%>">' border='0'></a>
    </itemtemplate>
    </asp:datalist>

    Thanks,
    Bob Lehmann
    Bob Lehmann, Nov 5, 2005
    #1
    1. Advertising

  2. Bob,

    without testing I'd assume that sth. like the following should work:

    Dim di As New DirectoryInfo(Current.Server.MapPath("images/position"))
    ThumbList.DataSource= di.GetFiles()
    ThumbList.DataBind()

    Does this help?

    Best regards

    Daniel Walzenbach


    "Bob Lehmann" <> schrieb im Newsbeitrag
    news:...
    > Hi,
    >
    > I'm trying to bind an ArrayList to a DataList.
    >
    > I get the error
    > DataBinder.Eval: 'System.String' does not contain a property with the name
    > Name.
    >
    > I don't know what property of ArrayList I should be using instead of
    > "Name"
    > in default.aspx.
    >
    > Can someone point me in the right direction?
    >
    > default.aspx.vb -
    > Dim di As New DirectoryInfo(Current.Server.MapPath("images/position"))
    > Dim FileList As FileInfo() = di.GetFiles()
    > Dim File As FileInfo
    > Dim ary As New ArrayList
    > For Each File In FileList
    > ary.Add(File.Name)
    > Next
    >
    > ThumbList.DataSource = ary
    > ThumbList.DataBind()
    >
    > default.aspx -
    > <asp:datalist id="ThumbList"
    > repeatdirection="Horizontal"
    > repeatcolumns="5"
    > gridlines="Both"
    > repeatlayout="Table"
    > itemstyle-cssclass="thumb"
    > runat="server">
    > <itemtemplate>
    > <img src='images/position/thumb/<%#DataBinder.Eval(Container,
    > "DataItem.Name")%>">' border='0'></a>
    > </itemtemplate>
    > </asp:datalist>
    >
    > Thanks,
    > Bob Lehmann
    >
    >
    Daniel Walzenbach, Nov 6, 2005
    #2
    1. Advertising

  3. Bob Lehmann

    Bob Lehmann Guest

    Thanks.

    I've tried that. However, the problem is that I need just the image name
    from the ArrayList.

    I've done this before, where each Name was a property of a class. In this
    case, I don't need this kind of granularity, and just want to grab the value
    from the ArrayList.

    Bob Lehmann


    "Daniel Walzenbach" <> wrote in message
    news:%...
    > Bob,
    >
    > without testing I'd assume that sth. like the following should work:
    >
    > Dim di As New DirectoryInfo(Current.Server.MapPath("images/position"))
    > ThumbList.DataSource= di.GetFiles()
    > ThumbList.DataBind()
    >
    > Does this help?
    >
    > Best regards
    >
    > Daniel Walzenbach
    >
    >
    > "Bob Lehmann" <> schrieb im Newsbeitrag
    > news:...
    > > Hi,
    > >
    > > I'm trying to bind an ArrayList to a DataList.
    > >
    > > I get the error
    > > DataBinder.Eval: 'System.String' does not contain a property with the

    name
    > > Name.
    > >
    > > I don't know what property of ArrayList I should be using instead of
    > > "Name"
    > > in default.aspx.
    > >
    > > Can someone point me in the right direction?
    > >
    > > default.aspx.vb -
    > > Dim di As New DirectoryInfo(Current.Server.MapPath("images/position"))
    > > Dim FileList As FileInfo() = di.GetFiles()
    > > Dim File As FileInfo
    > > Dim ary As New ArrayList
    > > For Each File In FileList
    > > ary.Add(File.Name)
    > > Next
    > >
    > > ThumbList.DataSource = ary
    > > ThumbList.DataBind()
    > >
    > > default.aspx -
    > > <asp:datalist id="ThumbList"
    > > repeatdirection="Horizontal"
    > > repeatcolumns="5"
    > > gridlines="Both"
    > > repeatlayout="Table"
    > > itemstyle-cssclass="thumb"
    > > runat="server">
    > > <itemtemplate>
    > > <img src='images/position/thumb/<%#DataBinder.Eval(Container,
    > > "DataItem.Name")%>">' border='0'></a>
    > > </itemtemplate>
    > > </asp:datalist>
    > >
    > > Thanks,
    > > Bob Lehmann
    > >
    > >

    >
    >
    Bob Lehmann, Nov 6, 2005
    #3
  4. Bob Lehmann

    Darren Kopp Guest

    Bob,

    You are adding the string to the array. Name is not a member of the string
    class (i know i just repeated the error). Change ary.Add(File.Name) to
    ary.Add(File) and your bind should work fine.

    For a more efficient approach, i believe that you can leave the
    ary.Add(File.Name) but change the binding command to <img
    src='images/position/thumb/<%#DataBinder.Eval(Container.DataItem)%>'>

    Hope that helps,
    Darren Kopp
    http://blog.secudocs.com/

    "Bob Lehmann" <> wrote in message
    news:...
    > Hi,
    >
    > I'm trying to bind an ArrayList to a DataList.
    >
    > I get the error
    > DataBinder.Eval: 'System.String' does not contain a property with the name
    > Name.
    >
    > I don't know what property of ArrayList I should be using instead of
    > "Name"
    > in default.aspx.
    >
    > Can someone point me in the right direction?
    >
    > default.aspx.vb -
    > Dim di As New DirectoryInfo(Current.Server.MapPath("images/position"))
    > Dim FileList As FileInfo() = di.GetFiles()
    > Dim File As FileInfo
    > Dim ary As New ArrayList
    > For Each File In FileList
    > ary.Add(File.Name)
    > Next
    >
    > ThumbList.DataSource = ary
    > ThumbList.DataBind()
    >
    > default.aspx -
    > <asp:datalist id="ThumbList"
    > repeatdirection="Horizontal"
    > repeatcolumns="5"
    > gridlines="Both"
    > repeatlayout="Table"
    > itemstyle-cssclass="thumb"
    > runat="server">
    > <itemtemplate>
    > <img src='images/position/thumb/<%#DataBinder.Eval(Container,
    > "DataItem.Name")%>">' border='0'></a>
    > </itemtemplate>
    > </asp:datalist>
    >
    > Thanks,
    > Bob Lehmann
    >
    >
    Darren Kopp, Jan 4, 2006
    #4
  5. Bob Lehmann

    jatin_aditya

    Joined:
    Jul 1, 2009
    Messages:
    1
    Bind ArrayList To DataList

    Hi Friends

    This code help u to solve ur problem
    try this

    DataBinder.Eval(Container,"DataItem")
    insted of
    DataBinder.Eval(Container,"DataItem.Name")
    jatin_aditya, Jul 1, 2009
    #5
    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. Saravanan Rathinavelu

    Iterate through ArrayList using an another ArrayList

    Saravanan Rathinavelu, Aug 16, 2003, in forum: ASP .Net
    Replies:
    3
    Views:
    2,726
    Natty Gur
    Aug 19, 2003
  2. Nevyn Twyll
    Replies:
    8
    Views:
    1,843
  3. Kaidi
    Replies:
    4
    Views:
    2,332
    Kaidi
    Jan 3, 2004
  4. =?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:
    564
    =?Utf-8?B?QVNQIERldmVsb3Blcg==?=
    Sep 26, 2006
  5. xz
    Replies:
    16
    Views:
    2,342
Loading...

Share This Page