<%@ Assembly Name="$SharePoint.Project.AssemblyFullName$" %>
<%@ Assembly Name="Microsoft.Web.CommandUI, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
<%@ Register Tagprefix="SharePoint" Namespace="Microsoft.SharePoint.WebControls" Assembly="Microsoft.SharePoint, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
<%@ Register Tagprefix="Utilities" Namespace="Microsoft.SharePoint.Utilities" Assembly="Microsoft.SharePoint, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
<%@ Register Tagprefix="asp" Namespace="System.Web.UI" Assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" %>
<%@ Import Namespace="Microsoft.SharePoint" %>
<%@ Register Tagprefix="WebPartPages" Namespace="Microsoft.SharePoint.WebPartPages" Assembly="Microsoft.SharePoint, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="RepeaterSampleUserControl.ascx.cs" Inherits="RepeaterSample.RepeaterSample.RepeaterSampleUserControl" %>
<style type="text/css">
.HeaderStyle
{
background-color:Navy;
color:white;
}
.ItemTemplateStyle
{
background-color:Orange;
color:white;
text-align:Center;
}
.AlternativeTemplateStyle
{
background-color:green;
color:white;
text-align:Center;
}
</style>
<table width="100%">
<asp:Repeater ID="rrTasks" runat="server">
<HeaderTemplate>
<tr>
<th class="HeaderStyle">Title</th>
<th class="HeaderStyle">Status</th>
<th class="HeaderStyle">Status</th>
</tr>
</HeaderTemplate>
<ItemTemplate>
<tr>
<td class="ItemTemplateStyle">
<a href="+<%# DataBinder.Eval(Container.DataItem, "ItemURL") %> +" style="text-decoration:none;color:White;"><%# DataBinder.Eval(Container.DataItem, "Title") %></a>
</td>
<td class="ItemTemplateStyle">
<%# DataBinder.Eval(Container.DataItem, "Status") %>
</td>
<td class="ItemTemplateStyle">
<%# DataBinder.Eval(Container.DataItem, "Priority") %>
</td>
</tr>
</ItemTemplate>
<AlternatingItemTemplate>
<tr>
<td class="AlternativeTemplateStyle">
<a href="+<%# DataBinder.Eval(Container.DataItem, "ItemURL") %> +" style="text-decoration:none;color:White;"><%# DataBinder.Eval(Container.DataItem, "Title") %></a>
</td>
<td class="AlternativeTemplateStyle">
<%# DataBinder.Eval(Container.DataItem, "Status") %>
</td>
<td class="AlternativeTemplateStyle">
<%# DataBinder.Eval(Container.DataItem, "Priority") %>
</td>
</tr>
</AlternatingItemTemplate>
</asp:Repeater>
</table>
_________________________________________________________________________________________
using System;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using Microsoft.SharePoint;
using System.Security;
using System.Linq;
using System.Data.Linq;
namespace RepeaterSample.RepeaterSample
{
public partial class RepeaterSampleUserControl : UserControl
{
string ItemURL = string.Empty;
string Title = string.Empty;
string Status = string.Empty;
string Priority = string.Empty;
protected void Page_Load(object sender, EventArgs e)
{
SPSecurity.RunWithElevatedPrivileges(delegate()
{
using (SPWeb objWeb = SPContext.Current.Web)
{
SPList lstTasks = objWeb.Lists["Tasks"];
SPListItemCollection myColl = lstTasks.Items;
if (myColl.Count > 0)
{
var query = from SPListItem item in myColl
orderby item["ID"] descending
select new
{
Title=item.Title.ToString(),
ItemURL=objWeb.Url +"/Lists/Tasks/DispForm.aspx?ID="+item["ID"].ToString()+"&Source="+Page.Request.Url,
Status=(item["Status"]==null) ? "Data UnAvailable" : item["Status"].ToString(),
Priority = (item["Priority"] == null)? "Data UnAvailable" : item["Status"].ToString(),
};
rrTasks.DataSource = query;
rrTasks.DataBind();
}
}
});
}
}
}
No comments:
Post a Comment