Prasad Bolla's SharePoint Blog

Click Here to go through the Interesting posts within my Blog.

Click Here to go through the new posts in my blog.

Thursday, December 01, 2011

QueryString Program without a single line of loop using SharePoint Object Model

Render Area Writing Custom Display Form.

Note:- When you are writing Code via QueryString dont use the Name ID. Use som,ething else.
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());
}

No comments:

Post a Comment