Link to home
Start Free TrialLog in
Avatar of Member_2_4426104
Member_2_4426104

asked on

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

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

Avatar of Member_2_4426104
Member_2_4426104

ASKER

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

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

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>")
ASKER CERTIFIED SOLUTION
Avatar of Member_2_4426104
Member_2_4426104

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial