|
code
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
GridView and XmlDataSourceDataField property of my BoundField controls to read actual xml node values. It only works if the DataField reads an xml node attribute. This is ridiculous. How can I read actual node values? I have a GridView control as follows ... <asp:GridView ID="GridView1" DataSourceID="XmlDataSource1" runat="Server"> <Columns> <asp:BoundField DataField="ProjectNbr" /> </Columns> </asp:GridView> Here is the XmlDataSource control ... <asp:XmlDataSource ID="XmlDataSourceControl1" DataFile="~/documents/checkforresults.xml" XPath="DocumentPacket/Folders/Folder" runat="Server" /> And here is the xml structure ... <DocumentPacket> <Folders> <Folder> <ProjectNbr>12345</ProjectNbr> <ProjectDesc>Project Description 12345</ProjectDesc> </Folder> <Folder> <ProjectNbr>54321</ProjectNbr> <ProjectDesc>Project Description 54321</ProjectDesc> </Folder> </Folders> </DocumentPacket> I keep getting an error "A field or property with the name 'Project Nbr' was not found on the selected data source.". If make the ProjectNbr and ProjectDesc values as attributes in the Folder node like <Folder ProjectNbr="12345" ProjectDesc="Project Description 12345"> everything works fine. Why does the DataField property of the BoundField control have to be an attribute in the xml node? Can't the DataField read an actual xml node value?????? Hi Ben,
You probably would have to use the XPath data binding expression within ItemTemplates, e.g. <asp:GridView ID="GridView1" runat="server" DataSourceID="XmlDataSource1" AutoGenerateColumns="false"> <Columns> <asp:TemplateField> <HeaderTemplate> Project #</HeaderTemplate> <ItemTemplate> <asp:Label ID="Label2" runat="server" Text='<%#XPath("ProjectNbr") %>'></asp:Label> </ItemTemplate> </asp:TemplateField> <asp:TemplateField> <HeaderTemplate> Description</HeaderTemplate> <ItemTemplate> <asp:Label ID="Label1" runat="server" Text='<%#XPath("ProjectDesc") %>'></asp:Label> </ItemTemplate> </asp:TemplateField> </Columns> </asp:GridView> Show quoteHide quote "Ben Schumacher" wrote: > Using an XmlDataSource to populate the GridView control, I can't set the > DataField property of my BoundField controls to read actual xml node values. > It only works if the DataField reads an xml node attribute. This is > ridiculous. How can I read actual node values? > > I have a GridView control as follows ... > > <asp:GridView ID="GridView1" DataSourceID="XmlDataSource1" runat="Server"> > <Columns> > <asp:BoundField DataField="ProjectNbr" /> > </Columns> > </asp:GridView> > > Here is the XmlDataSource control ... > > <asp:XmlDataSource ID="XmlDataSourceControl1" > DataFile="~/documents/checkforresults.xml" > XPath="DocumentPacket/Folders/Folder" runat="Server" /> > > And here is the xml structure ... > > <DocumentPacket> > <Folders> > <Folder> > <ProjectNbr>12345</ProjectNbr> > <ProjectDesc>Project Description 12345</ProjectDesc> > </Folder> > <Folder> > <ProjectNbr>54321</ProjectNbr> > <ProjectDesc>Project Description 54321</ProjectDesc> > </Folder> > </Folders> > </DocumentPacket> > > I keep getting an error "A field or property with the name 'Project Nbr' was > not found on the selected data source.". If make the ProjectNbr and > ProjectDesc values as attributes in the Folder node like <Folder > ProjectNbr="12345" ProjectDesc="Project Description 12345"> everything works > fine. Why does the DataField property of the BoundField control have to be > an attribute in the xml node? Can't the DataField read an actual xml node > value?????? > > > Thanks! I'll give it a try. Why would MS create that server control
(BoundField) to only read xml node attributes? Show quoteHide quote "Phillip Williams" <WEBSWAPP@newsgroups.nospam> wrote in message news:CC3585E9-F17D-40D8-A8E5-808270158D51@microsoft.com... > Hi Ben, > > You probably would have to use the XPath data binding expression within > ItemTemplates, e.g. > > <asp:GridView ID="GridView1" runat="server" DataSourceID="XmlDataSource1" > AutoGenerateColumns="false"> > <Columns> > <asp:TemplateField> > <HeaderTemplate> > Project #</HeaderTemplate> > <ItemTemplate> > <asp:Label ID="Label2" runat="server" > Text='<%#XPath("ProjectNbr") %>'></asp:Label> > </ItemTemplate> > </asp:TemplateField> > <asp:TemplateField> > <HeaderTemplate> > Description</HeaderTemplate> > <ItemTemplate> > <asp:Label ID="Label1" runat="server" > Text='<%#XPath("ProjectDesc") %>'></asp:Label> > </ItemTemplate> > </asp:TemplateField> > </Columns> > </asp:GridView> > > -- > HTH, > Phillip Williams > http://www.societopia.net > http://www.webswapp.com > > > "Ben Schumacher" wrote: > >> Using an XmlDataSource to populate the GridView control, I can't set the >> DataField property of my BoundField controls to read actual xml node >> values. >> It only works if the DataField reads an xml node attribute. This is >> ridiculous. How can I read actual node values? >> >> I have a GridView control as follows ... >> >> <asp:GridView ID="GridView1" DataSourceID="XmlDataSource1" >> runat="Server"> >> <Columns> >> <asp:BoundField DataField="ProjectNbr" /> >> </Columns> >> </asp:GridView> >> >> Here is the XmlDataSource control ... >> >> <asp:XmlDataSource ID="XmlDataSourceControl1" >> DataFile="~/documents/checkforresults.xml" >> XPath="DocumentPacket/Folders/Folder" runat="Server" /> >> >> And here is the xml structure ... >> >> <DocumentPacket> >> <Folders> >> <Folder> >> <ProjectNbr>12345</ProjectNbr> >> <ProjectDesc>Project Description 12345</ProjectDesc> >> </Folder> >> <Folder> >> <ProjectNbr>54321</ProjectNbr> >> <ProjectDesc>Project Description 54321</ProjectDesc> >> </Folder> >> </Folders> >> </DocumentPacket> >> >> I keep getting an error "A field or property with the name 'Project Nbr' >> was >> not found on the selected data source.". If make the ProjectNbr and >> ProjectDesc values as attributes in the Folder node like <Folder >> ProjectNbr="12345" ProjectDesc="Project Description 12345"> everything >> works >> fine. Why does the DataField property of the BoundField control have to >> be >> an attribute in the xml node? Can't the DataField read an actual xml >> node >> value?????? >> >> >> I ran into just this in the past couple of days. Microsoft has their way of
doing it and they are pro attributes for some reason (Check out Sql Server For XML Explicit). Anyway, the way around this for me was to use an XSL transformation to create attributes out of nodes. For example. Original XML <?xml version="1.0" standalone="yes"?> <applications> <application> <applicationkey>XXX</applicationkey> <applicationname>My Application</applicationname> <url>www.shawonline1.com</url> <owner>The Boxx</owner> <status>1</status> </application> </applications> XSL Transformation <?xml version="1.0"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msxsl="urn:schemas-microsoft-com:xslt"> <xsl:strip-space elements="*" /> <xsl:output method="xml" omit-xml-declaration="yes" indent="yes" standalone="yes" /> <xsl:template match="/"> <xsl:for-each select="applications"> <xsl:element name="applications"> <xsl:for-each select="application"> <xsl:element name="application"> <xsl:attribute name="applicationkey"> <xsl:value-of select="applicationkey" /> </xsl:attribute> <xsl:attribute name="applicationname"> <xsl:value-of select="applicationname" /> </xsl:attribute> <xsl:attribute name="url"> <xsl:value-of select="url" /> </xsl:attribute> <xsl:attribute name="owner"> <xsl:value-of select="owner" /> </xsl:attribute> <xsl:attribute name="status"> <xsl:value-of select="status" /> </xsl:attribute> </xsl:element> </xsl:for-each> </xsl:element> </xsl:for-each> </xsl:template> </xsl:stylesheet> Now for the code. XmlDataSource objXmlDS = new XmlDataSource(); objXmlDS.Data = strAppsXml; // Here is where you put the xsl in. objXmlDS.TransformFile = "~/RemapApplications.xsl"; // This is the xsl file name. gvApplications.DataSource = objXmlDS; gvApplications.DataBind(); This gave me the results I was looking for. Hope it helps. Scott. Show quoteHide quote "Ben Schumacher" <bschumac***@navegate.com> wrote in message news:%23$fpy8UOGHA.648@TK2MSFTNGP14.phx.gbl... > Thanks! I'll give it a try. Why would MS create that server control > (BoundField) to only read xml node attributes? > > "Phillip Williams" <WEBSWAPP@newsgroups.nospam> wrote in message > news:CC3585E9-F17D-40D8-A8E5-808270158D51@microsoft.com... > > Hi Ben, > > > > You probably would have to use the XPath data binding expression within > > ItemTemplates, e.g. > > > > <asp:GridView ID="GridView1" runat="server" DataSourceID="XmlDataSource1" > > AutoGenerateColumns="false"> > > <Columns> > > <asp:TemplateField> > > <HeaderTemplate> > > Project #</HeaderTemplate> > > <ItemTemplate> > > <asp:Label ID="Label2" runat="server" > > Text='<%#XPath("ProjectNbr") %>'></asp:Label> > > </ItemTemplate> > > </asp:TemplateField> > > <asp:TemplateField> > > <HeaderTemplate> > > Description</HeaderTemplate> > > <ItemTemplate> > > <asp:Label ID="Label1" runat="server" > > Text='<%#XPath("ProjectDesc") %>'></asp:Label> > > </ItemTemplate> > > </asp:TemplateField> > > </Columns> > > </asp:GridView> > > > > -- > > HTH, > > Phillip Williams > > http://www.societopia.net > > http://www.webswapp.com > > > > > > "Ben Schumacher" wrote: > > > >> Using an XmlDataSource to populate the GridView control, I can't set the > >> DataField property of my BoundField controls to read actual xml node > >> values. > >> It only works if the DataField reads an xml node attribute. This is > >> ridiculous. How can I read actual node values? > >> > >> I have a GridView control as follows ... > >> > >> <asp:GridView ID="GridView1" DataSourceID="XmlDataSource1" > >> runat="Server"> > >> <Columns> > >> <asp:BoundField DataField="ProjectNbr" /> > >> </Columns> > >> </asp:GridView> > >> > >> Here is the XmlDataSource control ... > >> > >> <asp:XmlDataSource ID="XmlDataSourceControl1" > >> DataFile="~/documents/checkforresults.xml" > >> XPath="DocumentPacket/Folders/Folder" runat="Server" /> > >> > >> And here is the xml structure ... > >> > >> <DocumentPacket> > >> <Folders> > >> <Folder> > >> <ProjectNbr>12345</ProjectNbr> > >> <ProjectDesc>Project Description 12345</ProjectDesc> > >> </Folder> > >> <Folder> > >> <ProjectNbr>54321</ProjectNbr> > >> <ProjectDesc>Project Description 54321</ProjectDesc> > >> </Folder> > >> </Folders> > >> </DocumentPacket> > >> > >> I keep getting an error "A field or property with the name 'Project Nbr' > >> was > >> not found on the selected data source.". If make the ProjectNbr and > >> ProjectDesc values as attributes in the Folder node like <Folder > >> ProjectNbr="12345" ProjectDesc="Project Description 12345"> everything > >> works > >> fine. Why does the DataField property of the BoundField control have to > >> be > >> an attribute in the xml node? Can't the DataField read an actual xml > >> node > >> value?????? > >> > >> > >> > >
ASP.NET 2.0 Easier than ASP? Gimmie a Break!
checking checkboxes per javascript in asp.net 2.0 treeview TabStrip - create tabs dynamicly on client-side Trouble with DataList Control Trouble with the DataList Control Compare Validator for Date AND Time hyperlink in a Calendar Control ASP.Net 2.0 Table not expanding 100% .NET 2.0 ImageButton control not submitting like form button Wizard + control validation |
|||||||||||||||||||||||