Back End Database
using System;
using System.ComponentModel;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using Microsoft.SharePoint;
using Microsoft.SharePoint.WebControls;
using System.Security;
namespace CHSample1.CHSample1
{
[ToolboxItemAttribute(false)]
public class CHSample1 : WebPart
{
string strError = string.Empty;
string strHTML = string.Empty;
protected override void Render(HtmlTextWriter
writer)
{
try
{
SPWeb currentWeb = SPContext.Current.Web;
SPList lst = currentWeb.Lists["Color"];
SPQuery sQuery = new SPQuery();
sQuery.Query = "<OrderBy><FieldRef
Name='ID' /></OrderBy>";
SPListItemCollection myColl =
lst.GetItems(sQuery);
if (myColl.Count > 0)
{
string strTable = string.Empty;
strTable += "<Table>";
foreach (SPListItem
item in myColl)
{
string strColor = string.Empty;
strColor =
item.Title.ToString();
int i = BindTaskCount(strColor);
strTable += "<Tr>";
strTable += "<Td style='background-color:"+strColor+"' Title='"+strColor+"' width='10'>";
strTable += " ";
strTable += "</Td>";
strTable += "<Td>";
strTable += " ";
strTable += "</Td>";
strTable += "<Td>";
strTable += i;
strTable += "</Td>";
strTable += "</Tr>";
}
strTable += "</Table>";
writer.Write(strTable);
}
}
catch (Exception
ex)
{
writer.Write(ex.ToString());
}
}
public int
BindTaskCount(string strColor)
{
SPWeb currentWeb = SPContext.Current.Web;
SPList lst = currentWeb.Lists["New Tasks"];
SPQuery sQuery = new SPQuery();
sQuery.Query = "<Where><Eq><FieldRef
Name='Color' /><Value Type='Lookup'>" + strColor + "</Value></Eq></Where><OrderBy><FieldRef
Name='Color' /></OrderBy>";
int count = 0;
SPListItemCollection myColl =
lst.GetItems(sQuery);
if (myColl.Count > 0)
{
count = myColl.Count;
}
return count;
}
}
}
No comments:
Post a Comment