populate checkboxlist from XmlDataSource (ASP.net 2.0)

G

Guest

can somebody please show me some code that will let me populate a
checkboxlist from the xmldatasource, and have the text property set to the
names in the xml file

thanks
you can also email me at (e-mail address removed)
 
A

Andrea Zani

mike said:
can somebody please show me some code that will let me populate a
checkboxlist from the xmldatasource, and have the text property set
to the names in the xml file

thanks

With this XML file:
<?xml version="1.0" encoding="utf-8" ?>
<root>
<item value="1" text="Value 1" />
<item value="2" text="Value 2" />
<item value="3" text="Value 3" />
</root>

And this code:
<asp:CheckBoxList ID="CheckBoxList1" runat="server"
DataSourceID="XmlDataSource1"
DataTextField="text" DataValueField="value">
</asp:CheckBoxList><asp:XmlDataSource ID="XmlDataSource1" runat="server"
DataFile="~/Data/XMLFile.xml"></asp:XmlDataSource>
 
G

Guest

<Lookup>
<Lookup_Entry>
<Ts>
<T>
<M>context</M>
<V>type</V>
<Va>Citizen</Va>
</T>
</Ts>
<U>.html</U>
</Lookup_Entry>
</Lookup>
example of xml file is above

code:
<asp:XmlDataSource ID="XmlDataSource1" runat="server" DataFile="~/Lookup
table.xml"
XPath='/Lookup/Lookup_Entry/Ts/T/Va[../../T[M = "context" and V
= "type"]]'>
</asp:XmlDataSource>
<asp:CheckBoxList
ID="CheckBoxList1"
runat="server"
DataSourceID="XmlDataSource1">
</asp:CheckBoxList>

Now how do i get each <Va> that is returned with the xmldatasource as a item
in my checkboxlist

displayed now when run is with a checkbox to the left of each item:
System.Web.UI.WebControls.XmlDataSourceNodeDescriptor
System.Web.UI.WebControls.XmlDataSourceNodeDescriptor
System.Web.UI.WebControls.XmlDataSourceNodeDescriptor
System.Web.UI.WebControls.XmlDataSourceNodeDescriptor
System.Web.UI.WebControls.XmlDataSourceNodeDescriptor
System.Web.UI.WebControls.XmlDataSourceNodeDescriptor
System.Web.UI.WebControls.XmlDataSourceNodeDescriptor

mike

Andrea Zani said:
mike said:
can somebody please show me some code that will let me populate a
checkboxlist from the xmldatasource, and have the text property set
to the names in the xml file

thanks

With this XML file:
<?xml version="1.0" encoding="utf-8" ?>
<root>
<item value="1" text="Value 1" />
<item value="2" text="Value 2" />
<item value="3" text="Value 3" />
</root>

And this code:
<asp:CheckBoxList ID="CheckBoxList1" runat="server"
DataSourceID="XmlDataSource1"
DataTextField="text" DataValueField="value">
</asp:CheckBoxList><asp:XmlDataSource ID="XmlDataSource1" runat="server"
DataFile="~/Data/XMLFile.xml"></asp:XmlDataSource>

--
AZ [Microsoft - .NET MVP]
Mia Home page: http://ciclismo.sitiasp.it
Asp.Net community: http://www.aspitalia.com
Il mio blog: http://blogs.aspitalia.com/az
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,581
Members
45,056
Latest member
GlycogenSupporthealth

Latest Threads

Top