Hi Joe,
Welcome to ASP.NET newsgroup.
As for the dropdownlist and xmlnodelist databinding problem you mentioned,
this is because the DropDownList is not a templated databound control(like
datalist ,repeater...), it's a normal databound control , the binded
dataitem need to provide strong-typed "Property", so that we can specify
the "DataTextField" , "DataValueField " for it.
As for your scenario, the binded datasource is a XmlNodeList which contains
list of XmlNode type. DropDownList can directly bind with such type and
retreive further info from the XmlNode's Attributes (or sub node....).
I think we have the following alternative means currently:
1. Still use DropDownList, however instead of databinding, we need to
manually use foreach loop to add ListItems into DropDownList according to
the XmlNodeList
2. Still using DataBinding approach, but we need to use template databound
control such as DataList or Repeater. For example, below is a simple
example that use Repeater control to bind a XmlNodeList and display a
select box:
======aspx===== ====
<asp:Repeater id="rptXml" runat="server">
<HeaderTemplate >
<select id="lstXml">
</HeaderTemplate>
<ItemTemplate >
<option value='<%#
((System.Xml.Xm lNode)Container .DataItem).Attr ibutes["id"].Value %>' >
<%#((System.Xml .XmlNode)Contai ner.DataItem).A ttributes["name"].Value
%></option>
</ItemTemplate>
<FooterTemplate >
</select>
</FooterTemplate>
</asp:Repeater>
=========code behind========= =
private void Page_Load(objec t sender, System.EventArg s e)
{
if(!IsPostBack)
{
BindData();
}
}
private void BindData()
{
string xmldata = @"<engines><eng ine name='test1' id='1' /><engine
name='test2' id='2' /></engines>";
XmlDocument doc = new XmlDocument();
doc.LoadXml(xml data);
XmlNodeList nodes = doc.SelectNodes ("/engines/engine");
rptXml.DataSour ce = nodes;
rptXml.DataBind ();
}
=============== ==============
Hope helps. Thanks,
Regards,
Steven Cheng
Microsoft Online Support
Get Secure!
www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)