OutPut:-
Backend List:-
Note:-
- Title is Single Lines of Text
- URL is Multi lines of Text
- Project Manager is the People Picker.
Here my Username is System Account. So I am able to see the
Project3 and Project1
Ascx
|
<%@ 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="RRTaskUserControl.ascx.cs" Inherits="RRTask.RRTask.RRTaskUserControl"
%>
<style type="text/css">
.HeaderStyle
{
background-color:Navy;
color:white;
}
.ItemTemplateStyle
{
background-color:Orange;
color:white;
text-align:left;
}
.AlternativeTemplateStyle
{
background-color:green;
color:white;
text-align:left;
}
</style>
<table width="100%">
<asp:Repeater ID="rrProjectsList" runat="server">
<HeaderTemplate>
<tr>
<th class="HeaderStyle">Project Name</th>
</tr>
</HeaderTemplate>
<ItemTemplate>
<tr>
<td class="ItemTemplateStyle">
<a href=<%# DataBinder.Eval(Container.DataItem,
"URL") %>
style="text-decoration:none;color:White;"><%# DataBinder.Eval(Container.DataItem,
"Title") %></a>
</td>
</tr>
</ItemTemplate>
<AlternatingItemTemplate>
<tr>
<td class="AlternativeTemplateStyle">
<a href=<%# DataBinder.Eval(Container.DataItem,
"URL") %>
style="text-decoration:none;color:White;"><%# DataBinder.Eval(Container.DataItem,
"Title") %></a>
</td>
</tr>
</AlternatingItemTemplate>
</asp:Repeater>
</table>
<asp:Label ID="lblMessage" runat="server" ></asp:Label>
|
Ascx.cs
|
using System;
using System.Web.UI;
using System.Web.UI.WebControls;
using
System.Web.UI.WebControls.WebParts;
using Microsoft.SharePoint;
using System.Security;
namespace RRTask.RRTask
{
public partial class RRTaskUserControl : UserControl
{
protected
void Page_Load(object
sender, EventArgs e)
{
getProjects();
}
public
void getProjects()
{
try
{
SPSecurity.RunWithElevatedPrivileges(delegate()
{
SPWeb
currentWeb = SPContext.Current.Web;
SPList
lst = currentWeb.Lists["Projects List"];
SPQuery
sQuery = new SPQuery();
sQuery.ViewFields = "<FieldRef Name='Title' /><FieldRef
Name='URL' />";
sQuery.ViewFieldsOnly = true;
sQuery.Query = "<OrderBy><FieldRef Name='ID'
Ascending='False' /></OrderBy><Where><Eq><FieldRef
Name='Project_x0020_Manager' /><Value Type='Integer'><UserID
Type='Integer' /></Value></Eq></Where>";
SPListItemCollection
myColl = lst.GetItems(sQuery);
if
(myColl.Count > 0)
{
rrProjectsList.DataSource = myColl.GetDataTable();
rrProjectsList.DataBind();
}
});
}
catch
(Exception Ex)
{
lblMessage.Text =
Ex.ToString();
}
}
}
}
|
No comments:
Post a Comment