databind - XmlNodeList to DropDownList

Discussion in 'ASP .Net Web Controls' started by Matthew.DelVecchio@CapitalOneAuto.com, Jun 16, 2005.

  1. Guest

    hello,

    i am attempting to do some databinding of an XmlNodeList to a
    DropDownList. id like to avoid looping thru my nodelist and hoped to do
    a simple .DataSource/.DataBind technique.

    for simplicity, lets say this is my xml:

    <people>
    <person name="Joe">[other child nodes w/ innertext]</person>
    <person name="Bob">[other child nodes w/ innertext]</person>
    <person name="Tim">[other child nodes w/ innertext]</person>
    </people>

    ....and this is my code-behind:

    'get person nodes
    Dim personNodes As XmlNodeList = xml.SelectNodes("//person")

    'bind to list
    ddlYear.DataSource = personNodes
    'ddlYear.DataTextField = ??
    ddlYear.DataBind()


    my desired result is a dropdownlist of items w/ text of:

    Joe
    Bob
    Tim

    ....how does one do this?


    thanks!
    matt
     
    , Jun 16, 2005
    #1
    1. Advertising

  2. Brock Allen Guest

    Fritz mentions some approaches here:

    http://msdn.microsoft.com/netframew...ry/en-us/dnaspp/html/aspn-hierdatabinding.asp

    -Brock
    DevelopMentor
    http://staff.develop.com/ballen



    > hello,
    >
    > i am attempting to do some databinding of an XmlNodeList to a
    > DropDownList. id like to avoid looping thru my nodelist and hoped to
    > do a simple .DataSource/.DataBind technique.
    >
    > for simplicity, lets say this is my xml:
    >
    > <people>
    > <person name="Joe">[other child nodes w/ innertext]</person>
    > <person name="Bob">[other child nodes w/ innertext]</person>
    > <person name="Tim">[other child nodes w/ innertext]</person>
    > </people>
    > ...and this is my code-behind:
    >
    > 'get person nodes
    > Dim personNodes As XmlNodeList = xml.SelectNodes("//person")
    > 'bind to list
    > ddlYear.DataSource = personNodes
    > 'ddlYear.DataTextField = ??
    > ddlYear.DataBind()
    > my desired result is a dropdownlist of items w/ text of:
    >
    > Joe
    > Bob
    > Tim
    > ...how does one do this?
    >
    > thanks!
    > matt
     
    Brock Allen, Jun 16, 2005
    #2
    1. Advertising

  3. Guest

    i dont think those really address what im talking about. to date, the
    simplest approach i can find is enumeration thru the nodelist and
    adding manually, like so:

    Dim node As XmlNode
    For Each node in personNodes
    ddlPeople.Items.Add(new ListItem(node.SelectSingleNode("@ID"),
    node.SelectSingleNode("@name")))
    Next

    ....thats 4 lines of code, which is good; but a loop, which is bad.

    it seems that the DropDownList's .DataTextField() and .DataValueField()
    methods are not robust enough to support anything other than a
    result-set's column names. thats pretty lame.

    seeing as XML is the glue beneath almost everything, even our friend
    the DataSet, i would think that XPATH support would be a no-brainer for
    a .DataSource of XML. i would like to be able to specify which
    nodes/attributes to use for field sources.

    additionally, if a multi-dimensional object is being assigned as the
    ..DataSource, then an index value for which to use as the
    ..DataTextField() and .DataValueField() would be logical.

    maybe in .NET 3.0, huh?


    thanks
    matt

    --
    Matt Del Vecchio
     
    , Jun 24, 2005
    #3
  4. Guest

    btw, i came across a cool new UI web technology, flash-based, w/ native
    support for XPATH databinding. it's called Laszlo, and it's open. check
    it out:

    http://www.openlaszlo.org/


    matt

    --
    Matt Del Vecchio
     
    , Jul 5, 2005
    #4
  5. Guest

    it seems that the DropDownList's .DataTextField() and .DataValueField()
    methods are not robust enough to support anything other than a
    result-set's column names. thats pretty lame.

    granted, you can load your xml into a DataSet and then use DTF & DVF to
    bind from there, but thats more overhead than necessary.

    seeing as XML is the glue beneath almost everything, even our friend
    the DataSet, i would think that XPATH support would be a no-brainer for
    a .DataSource of XML. i would like to be able to specify which
    nodes/attributes to use for field sources.

    additionally, if a multi-dimensional object is being assigned as the
    ..DataSource, then an index value for which to use as the
    ..DataTextField() and .DataValueField() would be logical.

    btw, i came across a cool new UI web technology, flash-based, w/ native
    support for XPATH databinding. it's called Laszlo, and it's open. check
    it out:

    http://www.openlaszlo.org/


    matt

    --
    Matt Del Vecchio
     
    , Jul 5, 2005
    #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. Kimberly Walker

    Dropdownlist adding data after databind

    Kimberly Walker, Oct 23, 2003, in forum: ASP .Net
    Replies:
    0
    Views:
    476
    Kimberly Walker
    Oct 23, 2003
  2. Roshawn Dawson

    Databinding syntax with xmlnodelist

    Roshawn Dawson, Jun 6, 2005, in forum: ASP .Net
    Replies:
    1
    Views:
    1,188
    Roshawn Dawson
    Jun 7, 2005
  3. Replies:
    0
    Views:
    1,676
  4. Raul

    Looping through XmlNodeList

    Raul, Mar 20, 2007, in forum: ASP .Net
    Replies:
    1
    Views:
    834
    =?Utf-8?B?TW9oYW1lZCBNb3NhbGVt?=
    Mar 21, 2007
  5. Michael
    Replies:
    0
    Views:
    245
    Michael
    Dec 29, 2003
Loading...

Share This Page