Tuesday, January 3, 2012

Querstring Program without a single line of loop

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;
namespace QuerystringProgramWithoutLoop.QuerystringProgramWithoutLoop
{
[ToolboxItemAttribute(false)]
public class QuerystringProgramWithoutLoop : WebPart
{
protected override void Render(HtmlTextWriter writer)
{
try
{
writer.Write("<Table width='100%'>");
if (Page.Request.QueryString["ItemID"] != null)
{
SPQuery sQuery = new SPQuery();
sQuery.Query = "<Where><Eq><FieldRef Name='ID' /><Value Type='Counter'>" + Page.Request.QueryString["ItemID"] .ToString()+ "</Value></Eq></Where>";
SPListItemCollection myColl = SPContext.Current.Web.Lists["SharePoint 2010 Concepts"].GetItems(sQuery);
if (myColl.Count > 0)
{
SPListItem item = myColl[0];
string strTitle = string.Empty;
string strStatus = string.Empty;
strTitle = item.Title.ToString();
strStatus = item["Status"].ToString().Substring(item["Status"].ToString().IndexOf('#') + 1);
writer.Write("<Tr>");
writer.Write("<Td>");
writer.Write("Concept Name");
writer.Write("</Td>");
writer.Write("<Td>");
writer.Write(strTitle);
writer.Write("</Td>");
writer.Write("</Tr>");
writer.Write("<Tr>");
writer.Write("<Td>");
writer.Write("Concept Status");
writer.Write("</Td>");
writer.Write("<Td>");
writer.Write(strStatus);
writer.Write("</Td>");
writer.Write("</Tr>");
}
else
{
writer.Write("<Tr>");
writer.Write("<Td>");
writer.Write("<Strong>");
writer.Write("Record was moved or deleted by another user");
writer.Write("</Strong>");
writer.Write("</Td>");
writer.Write("</Tr>");
}
}
else
{
writer.Write("<Tr>");
writer.Write("<Td>");
writer.Write("<Strong>");
writer.Write("No ListItem Present with this ItemID");
writer.Write("</Strong>");
writer.Write("</Td>");
writer.Write("</Tr>");
}
writer.Write("</Table>");
}
catch (Exception ex)
{
writer.Write(ex.ToString());
}
}
protected override void CreateChildControls()
{
}
}
}

No comments:

Post a Comment