Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP .Net Web Controls > databind - XmlNodeList to DropDownList

Reply
Thread Tools

databind - XmlNodeList to DropDownList

 
 
Matthew.DelVecchio@CapitalOneAuto.com
Guest
Posts: n/a
 
      06-16-2005
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

 
Reply With Quote
 
 
 
 
Brock Allen
Guest
Posts: n/a
 
      06-16-2005
Fritz mentions some approaches here:

http://msdn.microsoft.com/netframewo...atabinding.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




 
Reply With Quote
 
 
 
 
Matthew.DelVecchio@CapitalOneAuto.com
Guest
Posts: n/a
 
      06-24-2005
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

 
Reply With Quote
 
Matthew.DelVecchio@CapitalOneAuto.com
Guest
Posts: n/a
 
      07-05-2005
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

 
Reply With Quote
 
Matthew.DelVecchio@CapitalOneAuto.com
Guest
Posts: n/a
 
      07-05-2005
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

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Looping through XmlNodeList Raul ASP .Net 1 03-21-2007 08:40 AM
databind - XmlNodeList to DropDownList Matthew.DelVecchio@CapitalOneAuto.com ASP .Net 0 06-16-2005 06:57 PM
Databinding syntax with xmlnodelist Roshawn Dawson ASP .Net 1 06-06-2005 11:06 PM
BUG in DataBind? After .DataBind there are more DataGrid Items than DataSet Rows! Michael ASP .Net Datagrid Control 0 12-29-2003 07:47 PM
Dropdownlist adding data after databind Kimberly Walker ASP .Net 0 10-23-2003 02:09 AM



Advertisments