Repeater and XML Node List

Alrighty, 

so if I have an XmlNodeList as the data source for a repeater, in my
repeater, I would like to do things like:

<%# DataBinder.Eval(Container.DataItem, "ChildNodes[0].InnerText") %>

But everytime I do it says stuff like: 

'System.Xml.XmlChildNodes' does not allow indexed access.

Of course, it's perfectly happy to use
FirstChild.NextSibling.InnerText, but I'd like to use indexed methods
or properties, but it does not seem to work.

Here is sample code:

<%@ Page Language="C#" autoEventWireup="false"%>
<%@ Import Namespace="System.Xml" %>

<script language="c#" runat="server">

override protected void OnInit(EventArgs e)
{
	base.OnInit(e);
	this.Load += new System.EventHandler(this.Page_Load);
}

private void Page_Load(object sender, System.EventArgs e)
{
	XmlDocument d = new XmlDocument();
	d.LoadXml("<root><county><id>1</id><name>FULTON</name><state>GA</state></county><county><id>2</id><name>DE
KALB</name><state>GA</state></county></root>");

	myRepeater.DataSource = d.SelectNodes("//county");
	myRepeater.DataBind(); 
}
	
</script>

<html>
<body>

<h2>Counties List</h2>

<asp:Repeater id="myRepeater"  runat="server">
   <HeaderTemplate>
     <table>
        <tr><th>ID</th><th>County Name</th><th>State Name</th></tr>
   </HeaderTemplate>
	<ItemTemplate>
	 <tr>
	   <td><%# DataBinder.Eval(Container.DataItem,"FirstChild.InnerText")%></td>
	   <td><%# DataBinder.Eval(Container.DataItem,"FirstChild.NextSibling.InnerText")%></td>
	   <td><%# DataBinder.Eval(Container.DataItem,"FirstChild.NextSibling.NextSibling.InnerText")%></td>
	 </tr>
	</ItemTemplate>
    <FooterTemplate>
     </table>
    </FooterTemplate>
</asp:Repeater>

</body>
</html>
0
12/19/2003 2:06:30 AM
dotnet.xml 7266 articles. 0 followers. Follow

2 Replies
729 Views

Similar Articles

[PageSpeed] 2

How about not using DataBinder.Eval as in:

<%# ((XmlNode)Container.DataItem).ChildNodes[0].InnerText %>

-- 
HTH
Christoph Schittko [MVP]
Software Architect, .NET Mentor


"William Groombridge" <williamg75@hotmail.com> wrote in message
news:fce8ea39.0312181806.694212e3@posting.google.com...
> Alrighty,
>
> so if I have an XmlNodeList as the data source for a repeater, in my
> repeater, I would like to do things like:
>
> <%# DataBinder.Eval(Container.DataItem, "ChildNodes[0].InnerText") %>
>
> But everytime I do it says stuff like:
>
> 'System.Xml.XmlChildNodes' does not allow indexed access.
>
> Of course, it's perfectly happy to use
> FirstChild.NextSibling.InnerText, but I'd like to use indexed methods
> or properties, but it does not seem to work.
>
> Here is sample code:
>
> <%@ Page Language="C#" autoEventWireup="false"%>
> <%@ Import Namespace="System.Xml" %>
>
> <script language="c#" runat="server">
>
> override protected void OnInit(EventArgs e)
> {
> base.OnInit(e);
> this.Load += new System.EventHandler(this.Page_Load);
> }
>
> private void Page_Load(object sender, System.EventArgs e)
> {
> XmlDocument d = new XmlDocument();
>
d.LoadXml("<root><county><id>1</id><name>FULTON</name><state>GA</state></cou
nty><county><id>2</id><name>DE
> KALB</name><state>GA</state></county></root>");
>
> myRepeater.DataSource = d.SelectNodes("//county");
> myRepeater.DataBind();
> }
>
> </script>
>
> <html>
> <body>
>
> <h2>Counties List</h2>
>
> <asp:Repeater id="myRepeater"  runat="server">
>    <HeaderTemplate>
>      <table>
>         <tr><th>ID</th><th>County Name</th><th>State Name</th></tr>
>    </HeaderTemplate>
> <ItemTemplate>
> <tr>
>    <td><%#
DataBinder.Eval(Container.DataItem,"FirstChild.InnerText")%></td>
>    <td><%#
DataBinder.Eval(Container.DataItem,"FirstChild.NextSibling.InnerText")%></td
>
>    <td><%#
DataBinder.Eval(Container.DataItem,"FirstChild.NextSibling.NextSibling.Inner
Text")%></td>
> </tr>
> </ItemTemplate>
>     <FooterTemplate>
>      </table>
>     </FooterTemplate>
> </asp:Repeater>
>
> </body>
> </html>


0
12/19/2003 3:18:35 AM
Actually, that works perfect thanks.

Bill G.

"Christoph Schittko [MVP]" <christophdotnetINVALID@austin.rr.com> wrote in message news:<eSeDN7dxDHA.3744@TK2MSFTNGP11.phx.gbl>...
> How about not using DataBinder.Eval as in:
> 
> <%# ((XmlNode)Container.DataItem).ChildNodes[0].InnerText %>
> 
> -- 
> HTH
> Christoph Schittko [MVP]
> Software Architect, .NET Mentor
> 
> 
> "William Groombridge" <williamg75@hotmail.com> wrote in message
> news:fce8ea39.0312181806.694212e3@posting.google.com...
> > Alrighty,
> >
> > so if I have an XmlNodeList as the data source for a repeater, in my
> > repeater, I would like to do things like:
> >
> > <%# DataBinder.Eval(Container.DataItem, "ChildNodes[0].InnerText") %>
> >
> > But everytime I do it says stuff like:
> >
> > 'System.Xml.XmlChildNodes' does not allow indexed access.
> >
> > Of course, it's perfectly happy to use
> > FirstChild.NextSibling.InnerText, but I'd like to use indexed methods
> > or properties, but it does not seem to work.
> >
> > Here is sample code:
> >
> > <%@ Page Language="C#" autoEventWireup="false"%>
> > <%@ Import Namespace="System.Xml" %>
> >
> > <script language="c#" runat="server">
> >
> > override protected void OnInit(EventArgs e)
> > {
> > base.OnInit(e);
> > this.Load += new System.EventHandler(this.Page_Load);
> > }
> >
> > private void Page_Load(object sender, System.EventArgs e)
> > {
> > XmlDocument d = new XmlDocument();
> >
> d.LoadXml("<root><county><id>1</id><name>FULTON</name><state>GA</state></cou
> nty><county><id>2</id><name>DE
> > KALB</name><state>GA</state></county></root>");
> >
> > myRepeater.DataSource = d.SelectNodes("//county");
> > myRepeater.DataBind();
> > }
> >
> > </script>
> >
> > <html>
> > <body>
> >
> > <h2>Counties List</h2>
> >
> > <asp:Repeater id="myRepeater"  runat="server">
> >    <HeaderTemplate>
> >      <table>
> >         <tr><th>ID</th><th>County Name</th><th>State Name</th></tr>
> >    </HeaderTemplate>
> > <ItemTemplate>
> > <tr>
> >    <td><%#
>  DataBinder.Eval(Container.DataItem,"FirstChild.InnerText")%></td>
> >    <td><%#
>  DataBinder.Eval(Container.DataItem,"FirstChild.NextSibling.InnerText")%></td
> >
> >    <td><%#
> DataBinder.Eval(Container.DataItem,"FirstChild.NextSibling.NextSibling.Inner
> Text")%></td>
> > </tr>
> > </ItemTemplate>
> >     <FooterTemplate>
> >      </table>
> >     </FooterTemplate>
> > </asp:Repeater>
> >
> > </body>
> > </html>
0
12/20/2003 6:07:00 AM
Reply:

Similar Artilces:

Random access of XML file
I have the XML file which has a structure similar to one I pasted at the end of this post. As you can see many elements are using different id attributes. For example element Window uses WinID attribute as ID, the ViewData uses ViewID attribute as an ID and so on. I need to read this file without assuming what is the order of the elements, in other words I can't read it sequentially. The reason for this requirement is that whole WindowsInfo element might be missing for example or Object Info might be first and WindowsInfo second etc. Since many elements have the same name and diffe...

need assistance with sorting a list of numbers
I've tried to achieve this problem with formulas and lookups and if statements and conditinal formatting however was not able to achieve desired results, so asking for help since I am not good with XL marcros..if someone can start me up I can navigate myself.. There is a list.. say of numbers and there is a possiblity that numbers will be repeats like: 12345 fail 12345 fail 12345 pass 11111 fail 11111 pass 22222 pass 33333 fail 33333 fail 44444 pass I want to read say A1 (numbers) disregard the repeats and put info A2 beside it 12345 fail fail pass 11111 fail pass 22222 pass 333...

Re: Re: api to check wheter xml is well formed #2
You mean the XmlTextReader. Ashish wrote: > Are there any functions in .Net which can be used to verify whether xml is > well formed? That's quite unusual requirement. Usually, when XML is built using XML API such as XmlTextWriter you don't need to check if it's well-formed - you can trust standard API. When your XML is loaded into in-memory store, such as XmlDocument - it's well-formed by definition. And when you just have a string or file and want to check it's well-formdness, use XmlTestReader: XmlReader r = new XmlTextReader(...); try { while (r.Read()...

Set public folder as default address list
Is there a way that I can set a public contact folder as the default address list when composing a message on all of my clients? JBeckett [MCSA] <JBeckettMCSA@discussions.microsoft.com> wrote: > Is there a way that I can set a public contact folder as the default > address list when composing a message on all of my clients? This is an Outlook thing. You can change the Outlook Address Book to display whatever you like as its initial view, in the settings in the address book menu, I believe. You don't want to make Outlook do *lookups* first from the public contacts folder, ...

Generate a unique number of list
Hey all, I have a list of number which some is repeated, how can I regenerate a list with unique number. e.g 1 2 1 5 3 5 Expected Result 1 2 5 3 Thanks for any one who can help. -- Terence Chan ------------------------------------------------------------------------ Terence Chan's Profile: http://www.excelforum.com/member.php?action=getinfo&userid=26963 View this thread: http://www.excelforum.com/showthread.php?threadid=467164 Hi Terence One way Mark your range of data, Data>Filter>Advanced Filter and Select Unique values only. Copy the data to a new location. Rega...

Automatically Deleting a List from Another List
Hello There, I'm new to these parts and I'm hoping someone can help me. I have a simple email list of 4000 addresses (List A) and some are no good. I've made a separate list (List B) of those and want to delete all of them from the initial list (List A). Is there a way of doing this without doing it manually? A formula of some sort? Thank you for your help. Look in the vba help index for FIND (FINDNEXT if more than one). Then a for each loop -- Don Guillett Microsoft MVP Excel SalesAid Software dguillett1@austin.rr.com "ddethomas" <ddethomas@discussions.micros...

Pretty print XML?
I am sure this has been asked enough to warrant an FAQ but I could not find it. Does anyone have some code and maybe an XSLT stylesheet that would allow me to transform an XML string to a "pretty" version (nodes indented on separate lines, etc.)? Thank you for your help. Kevin Kevin Burton wrote: > I am sure this has been asked enough to warrant an FAQ but I could not > find it. > > Does anyone have some code and maybe an XSLT stylesheet that would allow > me to transform an XML string to a "pretty" version (nodes indented on > separate lines, et...

XML Root Node
I have a file I'm using as a Configuration file (configuration as in options and such). When I create the xml file in the .Net IDE, it places the following (snip): <Configuration xmlns="Blah"> </Configuration> This is the way I'd like it but it doesn't work this way :( When I validate it against the xsd file, it says that it's invalid. (Can't remember error, don't have time to reproduce). The fix is changing it to the following: <cfg:Configuration xmlns:cfg="Blah"> </cfg:Configuration> So, just need 1 of the two (...

Buils your own mailing list!
http://www.magictools.nl/list/346/ ...

how to have excel repeat a template on each page of each workshee.
i have created a template that i want to have on each page of each worksheet. is there command to make this happen/ You can create a new default template, with your preferred settings: Open a new workbook. Copy your template onto each worksheet Choose Save As From the Save As Type dropdown, choose Template (*.xlt) Name the File "Book.xlt" Save it in the XLStart folder (usually in Program Files/Microsoft Office/Office) When you click the New button on the toolbar, the new workbook will be based on this template. If you want new sheets to be inser...

Paragraph spacing of bulleted lists
I am trying to increase the paragraph spacing between my bulleted lines but want to keep the line spacing at 1 line. When I try to change the paragraph spacing, it accepts and displays the number I choose (e.g., 3pts, 6pts) but it does not make the change. What can I do to enable paragraph spacing between bullets? -- Mama G There's an inconspicuous box in the Format Paragraph pane for something like "Don't Add Space Between Paragraphs of the Same Style." Uncheck that. (Note that you're not limited to the Space After numbers in the dropdown -- you can t...

Looking for a way how to get currently selected item from List control
Hi, guys. There is a task. I have a window that is something like CListCtrl (but different framework, not MFC). I know only the HWND for that window. Inside are items. In fact it looks like usual ListCtrl but with some options like background and small buttons in the bottom to add/delete items. So I'm looking for a way how to find out which item is currently selected. I mean i need coordinates of that item. Is it possible to do using some WinAPI functions or so? Thank you. -- ---- German Koninin --------------------------------------- For every complex problem, there's solution t...

Is there a template available for a grocery list?
In my older version of Windows, I had a template for a grocery list. It was in the Works tool. In my newer desktop, Windows XP, I don't seem to have one in Word or Publisher. Microsoft Online did not have any either. Any suggestions on where I might find one? The Cook wrote: > In my older version of Windows, I had a template for a grocery list. It was > in the Works tool. In my newer desktop, Windows XP, I don't seem to have one > in Word or Publisher. Microsoft Online did not have any either. Any > suggestions on where I might find one? takes less typing on...

Macro to check data from excel list against access query and return value back to excel
(I posted this yesterday but am tryign to make it clearer) I have an excel list with "name" and "title" and there are many erros and mis-spellings. I havbe an acess quesry that has the correct names and titles and also some mis-spellings and foreign language spellings pointing to the correct english name and title. I would like to write a macro in excel to do a lookup of the excel value in the access quesry and find EITHER an exact match or close match and return the value of a specified field back into an excel column. Here is a hypothetic example: Access list: PK=Van G...

Contact List
Anyone know of a simple -- painless -- non frustrating method to compile a folder with say 15 of my existing contacts within OUTLOOK 2002 (using Office XP as well)... complete with company name & full address. Intention is to email the folder as an attachment. This sounds quite simple, but has someone actually completed the task?? Thanks in advance for correct & detailed instructions. ...

2nd cry for help-3 variable length lists of data that need to be concatenated in to one column
I have 3 variable length lists of data that need to be concatenated in to one column. Presently the following formula works (This is typed in to A1 and copied down the column using the drag handle so in cell A2 refs to C1,D1,E1 are automatically changed to C2,D2,E2 and so on): =IF(ROW()<=COUNTA(C:C),C1,IF(ROW()<=(COUNTA(C:C)+COUNTA(D:D)),OFFSET(D1,(COU NTA(C:C)),0,1,1),IF(ROW()<=(COUNTA(C:C)+COUNTA(D:D)+COUNTA(E:E)),OFFSET(E1,- (COUNTA(C:C)+COUNTA(D:D)),0,1,1),""))) Result - a list of data in column A which is the list of data in column C plus data in column D plus ...

Replace INI with XML
Looking for sample VB6 code to replace the functionality of INI related code with code to do the same using XML. Googling did not help me. WriteXMLString sSec,sKey, sItem sItem=ReadXMLString(sSec,sKey) DeleteXMLString(sSec,sKey) vArray=ReadXMLSection(sSec) DeleteXMLSection(sSec) etc. "Bee" <Bee@discussions.microsoft.com> wrote in message news:495D3696-628D-4266-A0A0-750E483A27D7@microsoft.com... > Looking for sample VB6 code to replace the functionality of INI related code > with code to do the same using XML. Googling did not help me. > WriteXMLS...

Compare two XML Files and save to One
Hi all, I feel like this question has been asked before but I just cannot seem to find a good answer. Q: Is there a way to have two XML files and compare them and save them to one. Example: XML-A: <Season> <Fruit>Orange</Fruit> <Fruit>Strawberry</Fruit> </Season> XML-B: <Season> <Fruit>Orange</Fruit> <Fruit>Banana</Fruit> </Season> Output to XML-C would be: <Season> <Fruit>Orange</Fruit> <Fruit>Strawberry</Fruit> <Fruit>Banana</Fruit> </Season> I downloaded and ins...

combo box on a form, I want it to list the maximum number of marks
I have a combo box on a form, I want it to list the maximum number of marks allowed for a task. So in tbltask table I have set the following: Task Name Max Mark Task1 3 Task2 10 So on a form will have the task1 and task2 listed on the it and I want the combo box next to the task to list all of the marks up to and including the maximum mark: e.g. Student Name Task Mark (Combo box would list the following numbers) a Task1 1,2,3 b Task2 1,2,3,4,5,6,7,8,9,10 c Task1 1,2,3 On M...

Data Validation list #6
I have a data validation cell that controls a pivot table. I want to help the user browse through the list that appear in the cell. It is a long list. I've seen some lists that prompt the names with the letters that you press in the key board. How can I make my list work like that. Thank you! FA DV drop-downs are not capable of providing autocomplete. For workaround using a combo-box see Debra Dalgleish's site. http://www.contextures.on.ca/xlDataVal10.html Gord Dibben Excel MVP On Thu, 29 Sep 2005 06:29:05 -0700, "FA" <FA@discussions.microsoft.com> wrot...

Contacts List #4
Could you please tell me how to change the "default" contacts list from Global to contacts? When clicking the "to" button, the address book seems to want to look in global contacts, when I would like to it just display the contacts. Using Outlook 2003. Thank you for your help. Open your Address Book (Ctrl+Shift+B) and select Tools->Options. Set your order for which contacts folder you use first there. -- Milly Staples [MVP - Outlook] ALWAYS post your Outlook version! Post all replies to the group to keep the discussion intact. How to ask a question: http://su...

numbered lists
I installed Word 2002 in my new Windows 7 laptop in addition to the Office 2007 I had previously installed and noticed something weird when I create a numbered list as I type. The way I recall it, when I want to go to next level of numbering I would press enter, and when the next number in sequence appeared I would hit tab to move it to the next indented level. Now, when I hit tab, it does nothing. If I go to the number and hit tab, it deletes the number and moves the text one level forward. I cannot create a sublevel. Is there a Word option I am missing? I went to AutoCorr...

Publish a PF Contacts folder as an address list
Hi Using Exchange Server 2003, is it possible to publish or query a Public Folder Contacts folder as an address list in Exchange 2003 to appear under the All Address Lists. I want this available for all users to view. I know the contact folder can be added by each user as an email address book. Thanks RajiA Raji Arulambalam wrote: > Hi > > Using Exchange Server 2003, is it possible to publish or query a > Public Folder Contacts folder as an address list in Exchange 2003 to > appear under the All Address Lists. > > I want this available for all users to view. > &...

Runtime Error 381 Couldn't set list property, invalid array index
I opened a 97 spreadsheet in 2003 and now each time a user form is initialized a runtime error comes up in the following line in the vba code: ComboDeptNum.List = Sheets("Definitions").Range("$J$1:$I$12") It is the same thing if I specify a named range: ComboDeptNum.List = Sheets("Definitions").Range("DeptList") This exact same codes works fine in 97 and the security is set to low in 2003. The number of columns is set propoerly but the list box just won't load values. I'm a newbie to Excel vba but have more experience with Access and never sa...

I need to manage an email mailing list
Can anyone suggest an add-inn that can help Outlook 2003 managean email mailing list. I need to manage opt in's and outs etc -- Stephen Connolly www.constructiveearth.com "Stephen Connolly" <StephenConnolly@discussions.microsoft.com> wrote in message news:BD98D3E5-48A0-4883-9349-5DA466269D43@microsoft.com... > Can anyone suggest an add-inn that can help Outlook 2003 managean email > mailing list. I need to manage opt in's and outs etc > -- > Stephen Connolly > www.constructiveearth.com Search www.slipstick.com for third party utilities that might h...