Here i'v developed a webpart for showing KPI indicators which are binded as desired
i have used a literal control and binded a my display structure in this literal control.
Code
//inialization
private LiteralControl Literal1;
SPSiteoCurrentSite = null;
SPWeb oweb =null;
int count;
DataTable dt =new DataTable();
string strStruct;
In CreateChildControls()
Literal1 = new LiteralControl();
Literal1.Load += new EventHandler(Literal1_Load);
Controls.Add(Literal1);
-------
on load event of Literal Control i'll be calling my Core functionlity which will be binded with this literal control.
MyFunction()
{
try {
count = 0;
//oCurrentSite = new
SPSite("http://syngdcds0138:1111");
oCurrentSite = SPContext.Current.Site;
oweb = oCurrentSite.OpenWeb();
oweb.AllowUnsafeUpdates = true;
SPList oProjectName = oweb.Lists["Tasks"];
SPQuery Query1;
DataTable Dtable;
DataView Dview;
SPListItemCollection items1;
SPUser currentUser = oweb.CurrentUser;
string UNAme = currentUser.Name;
Query1 = new SPQuery();
Dtable = new DataTable();
Dview = new DataView();
Query1.Query = "<Where><Eq><FieldRef Name='AssignedTo' /><Value Type='User'>" +
currentUser.Name + "</Value></Eq></Where>";
items1 = oProjectName.GetItems(Query1);
strStruct = "<div>" + "<table>";
foreach (SPListItem objItem in items1)
{//Pending Completed Overdue
string picture = string.Empty;
if (objItem["Status"].ToString() == "Overdue")
{ picture = @"~/_LAYOUTS/Images/ico-task-overdue.jpg";
}
else if (objItem["Status"].ToString() == "Completed")
{ picture = @"~/_LAYOUTS/Images/ico-task-Completed.jpg";
}
else
{picture = @"~/_LAYOUTS/Images/ico-task-Pending.jpg";
}
string[] CreatedBy = objItem["Created By"].ToString().Split('#');
string AssignedBY = CreatedBy[1];
string DDt = Convert.ToDateTime(objItem["DueDate"].ToString()).ToShortDateString();
strStruct += "<tr>" + "<td colspan=2 align='left'>" + "<img src='" + ResolveUrl(picture) + "'
/> " + "<a style='text-align:right; font-size:12px;' href='" + oweb.Url +
"/Lists/" + oProjectName.Title + "/DispForm.aspx?ID=" + objItem["ID"].ToString() + "&Source=" + oweb.Url + "'>" + objItem["Title"].ToString() + "</a>" + "</td></tr>" + "<tr><td colspan=2 style= 'font-family:Arial; font-size:xx-small;'>Due Date:" + DDt + " Assigned By:"
+ AssignedBY + " </td></tr>";
}
strStruct += "<tr><td></td><td> <a href='" + oweb.Url + "/Lists/" + oProjectName.Title + "/Allitems.aspx'>More>></a>" + "</td></tr>" + "<tr>" + "<td><img
src='~/_LAYOUTS/images/ico-task-Completed.jpg'> Completed " + "<img
src='~/_LAYOUTS/images/ico-task-Pending.jpg'> Pending " + "<img
src='~/_LAYOUTS/images/ico-task-overdue.jpg'> Overdue </td>"
+ "</tr>" + "</table></div>";
Literal1.Text = strStruct;
}
catch (Exception ee) { //Error}
}
Revert your comments for this article
No comments:
Post a Comment
Thanks for your valuable comments