Below is example code implementing the asp:ListView control in a SharePoint
page. Bound data comes from the SPDataSource control.
The SelectCommand
is in the CAML query language which is XML based. The query looks for all
Calendar events ending today or later, row limit of 4, sorted by start date. You
can also use parameters for a dynamic SelectCommand:
http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.webcontrols.spdatasource.selectparameters.aspx
<asp:ListView ID="ListView1"
runat="server" DataSourceID="spDataSource1">
<LayoutTemplate>
<div style="background-color: #fffddd; padding: 10px; width: 200px">
<asp:PlaceHolder ID="itemPlaceholder"
runat="server"></asp:PlaceHolder>
</div>
</LayoutTemplate>
<ItemTemplate>
<p
style="font-size:small;">
<a
href="/examples/Lists/Events//DispForm.aspx?ID=<%# Eval("ID") %>"
style="color:#787878"><span style='text-decoration:none;<%#
Eval("Category").Equals("Holiday") ? "font-weight:bold" : "font-weight:normal"
%>'><%# Eval("DisplayDateTime").ToString().Substring(8)
%></span><br />
<span style="font-style:italic"><%#
Eval("Title") %></span></a></p>
</ItemTemplate>
</asp:ListView>
<SharePointWebControls:SPDataSource
runat="server" ID="spDataSource1" DataSourceMode="List"
SelectCommand="<Query><Where><Geq><FieldRef Name='EndDate'
/><Value Type='DateTime'><Today
/></Value></Geq></Where><OrderBy><FieldRef
Name='EventDate' Ascending='True'
/></OrderBy><RowLimit>4</RowLimit></Query>">
<SelectParameters> <asp:Parameter Name="WebUrl" DefaultValue="/examples/" /> <asp:Parameter Name="ListName"
DefaultValue="Events" /> </SelectParameters>
</SharePointWebControls:SPDataSource>
No comments:
Post a Comment