[Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

linq: error on nested listview eval("date")

Posted on 2009-04-30
4
Medium Priority
?
706 Views
Last Modified: 2013-11-11
Hi,
I am getting an error on the nested listview:
System.Web.HttpException: DataBinding: 'System.Char' does not contain a property with the name 'date'.

on here:
<td><%# Eval("date") %></td>

My code is as follow
<%@ Page Language="vb" AutoEventWireup="false"    %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title></title>
<script runat = server>
        Protected Sub listsource_Selecting(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.LinqDataSourceSelectEventArgs) Handles listSource.Selecting
		  
            Dim xd As XDocument = XDocument.Parse("<courseList>" & _
          "<category code='4wd'  >" & _
            "<product code='lr' title='4wd Bush Driving'>" & _
              "<duration>1 Day</duration>" & _
				  "<dates><date>june 5</date></dates>" & _
            "</product>" & _
            "<product code='hr' title='4wd Defensive Driving'>" & _
              "<duration>1 Day</duration>" & _
				  "<dates><date>june 5</date></dates>" & _
            "</product>" & _
            "<product code='sr' title='Self-Recovery'>" & _
              "<duration>1 Day</duration>" & _
				  "<dates><date>june 5</date></dates>" & _
            "</product>" & _
          "</category>" & _
        "</courseList>")
 
            Dim query = From q In xd...<product> _
                  Where Not (q.parent.@code = "ds" or q.parent.@code = "other") _
						Select New With { _
							.title = q.@title, _
							.duration = q.<duration>.Value, _ 
							.dates = q.<dates>.Value, _
							.date = q.<dates>.<date>.Value _
											 } 
            e.Result = query
        End Sub
    </script>
</head>
<body>
<form id="form1" runat="server">
  <div>
    <asp:ScriptManager ID="scriptManager" runat="server" />
    <asp:LinqDataSource 
      		ID="listSource" 
      		runat="server" 
      		OnSelecting="listsource_Selecting" />
    <asp:UpdatePanel ID="upd" runat="server">
    <ContentTemplate>
    <asp:ListView ID="dates" runat="server" DataSourceID="listsource" >
    <LayoutTemplate>
    <div id="datatable">
      <table border="1" class="prodtbl" runat="server">
        <tr class="mainheader">
          <th > <asp:LinkButton ID="btnSortName" 
                       runat="server" CommandName="Sort" 
                       CommandArgument="title" Text="Course" />
          </th>
          <th> <asp:LinkButton ID="btnSortDuration" 
                     runat="server" CommandName="Sort" 
                     CommandArgument="duration" Text="Duration" />
          </th>
          <th> <asp:LinkButton ID="btnSortDate" 
                      runat="server" CommandName="Sort" 
                      CommandArgument="dates" Text="Dates" />
          </th>
        </tr>
        <tr id="itemPlaceholder" runat="server" />
        </tr>
        
      </table>
    </div>
  </div>
  </LayoutTemplate>
  <ItemTemplate>
    <tr id="row" >
      <td><%# Eval("title") %></td>
      <td><%# Eval("duration") %></td>
      <asp:ListView ID="lvItems" runat="server" DataSource='<%# Eval("dates") %>'>
        <LayoutTemplate>
          <td><asp:PlaceHolder runat="server" ID="itemPlaceholder" /></td>
        </LayoutTemplate>
        <ItemTemplate>
          <%# Eval("date") %>
        </ItemTemplate>
      </asp:ListView>
    </tr>
  </ItemTemplate>
  </asp:ListView>
  </ContentTemplate>
  </asp:UpdatePanel>
  </div>
</form>
</body>
</html>

Open in new window

0
Comment
Question by:Tania_Farmer
  • 4
4 Comments
 

Author Comment

by:Tania_Farmer
ID: 24268935
Hi,
I got this nested query to work but its only giving me the first item in <date> as opposed to the whole list.

T
Dim xd As New XDocument
          xd = XDocument.Load (Server.MapPath("/App_Data/courseList.xml"))
					
	Dim query = From q In xd...<product> _
		    Where Not (q.parent.@code = "ds" or q.parent.@code = "other") _
		    Order By q.@title _
	            Select New With { _
			.title = q.@title, _
			.duration = q.<duration>.Value, _ 
			.dates = (From d In q.<dates> _
			Select New With {.date = d.<date>.Value}) _	
											 } 			 
						e.Result = query
 
End Sub

Open in new window

0
 

Author Comment

by:Tania_Farmer
ID: 24268946
Hi,
Forgot to mention had changed the xml:

   "<category code='4wd'  >" & _
            "<product code='lr' title='4wd Bush Driving'>" & _
              "<duration>1 Day</duration>" & _
              "<dates><date>june 5</date></dates>" & _
              "<dates><date>june 6</date></dates>" & _
              "<dates><date>june 7</date></dates>" & _
            "</product>" & _
            "<product code='hr' title='4wd Defensive Driving'>" & _
              "<duration>1 Day</duration>" & _
              "<dates><date>june 8</date></dates>" & _
              "<dates><date>june 9</date></dates>" & _
              "<dates><date>june 10</date></dates>" & _
            "</product>" & _
            "<product code='sr' title='Self-Recovery'>" & _
              "<duration>1 Day</duration>" & _
              "<dates><date>june 2</date></dates>" & _
              "<dates><date>june 3</date></dates>" & _
              "<dates><date>june 4</date></dates>" & _
            "</product>" & _
          "</category>" & _
        "</courseList>")

Open in new window

0
 

Author Comment

by:Tania_Farmer
ID: 24269006
Sorry - rushing to much.

  "<category code='4wd'  >" & _
            "<product code='lr' title='4wd Bush Driving'>" & _
              "<duration>1 Day</duration>" & _
              "<dates>"  & _
                   "<date>june 8</date>" & _
                   "<date>june 9</date>" & _
                   "<date>june 10</date>" & _
               "</dates>" & _
            "</product>" & _
            "<product code='hr' title='4wd Defensive Driving'>" & _
              "<duration>1 Day</duration>" & _
              "<dates>"  & _
                   "<date>june 18</date>" & _
                   "<date>june 19</date>" & _
                   "<date>june 20</date>" & _
               "</dates>" & _
            "</product>" & _
            "<product code='sr' title='Self-Recovery'>" & _
              "<duration>1 Day</duration>" & _
              "<dates>"  & _
                   "<date>june 28</date>" & _
                   "<date>june 29</date>" & _
                   "<date>june 30</date>" & _
               "</dates>" & _
            "</product>" & _
          "</category>" & _
        "</courseList>")
0
 

Accepted Solution

by:
Tania_Farmer earned 0 total points
ID: 24271342
After a great amount of pain - got it:

 Dim xd As New XDocument
          xd = XDocument.Load (Server.MapPath("/App_Data/courseList.xml"))
                              
      Dim query = From q In xd...<product> _
             Where Not (q.parent.@code = "ds" or q.parent.@code = "other") _
            Select New With { _
                    .title = q.@title, _
                  .duration = q.<duration>.Value, _
                  .dates = (From d In q.<dates>.<date> _
                              Select New With { _
                                          .date = d.Value}) _      
                                                                   }                   
                                    e.Result = query
0

Featured Post

Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In my previous two articles we discussed Binary Serialization (http://www.experts-exchange.com/A_4362.html) and XML Serialization (http://www.experts-exchange.com/A_4425.html). In this article we will try to know more about SOAP (Simple Object Acces…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Despite its rising prevalence in the business world, "the cloud" is still misunderstood. Some companies still believe common misconceptions about lack of security in cloud solutions and many misuses of cloud storage options still occur every day. …
Look below the covers at a subform control , and the form that is inside it. Explore properties and see how easy it is to aggregate, get statistics, and synchronize results for your data. A Microsoft Access subform is used to show relevant calcul…
Suggested Courses
Course of the Month20 days, 10 hours left to enroll

868 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question