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.

Tuesday, February 07, 2012

How to bind a Simple Dynamic HTML Table from SharePoint Links List

try
            {
                SPSecurity.RunWithElevatedPrivileges(delegate()
                {
                    SPWeb currentWeb = SPContext.Current.Web;
                    SPList lstRecipeeLinks = currentWeb.Lists["Recipees Links"];
                    SPQuery sQuery = new SPQuery();
                    sQuery.Query = "<OrderBy><FieldRef Name='URL' /></OrderBy>";
                    sQuery.ViewFields = "<FieldRef Name='URL' />";
                    SPListItemCollection recipeeColl = lstRecipeeLinks.GetItems(sQuery);
                    if (recipeeColl.Count > 0)
                    {
                        writer.Write("<Table width='100%' cellpadding='0' cellspacing='0' border='1' borderColorDark='blue'>");
                        writer.Write("<Tr>");
                        writer.Write("<Td bgcolor='Blue' Colspan='2'>");
                        writer.Write("</Td>");
                        writer.Write("</Tr>");
                        writer.Write("<Tr>");
                        writer.Write("<Td style='font-size:x-small;font-weight:bold;' Align='Center' Colspan='2'>");
                        writer.Write("Indian Recipee Links");
                        writer.Write("</Td>");
                        writer.Write("</Tr>");
                        writer.Write("<Tr>");
                        writer.Write("<Td bgcolor='Blue' Colspan='2'>");
                        writer.Write("</Td>");
                        writer.Write("</Tr>");
                        int k = 1;
                        foreach (SPListItem item in recipeeColl)
                        {
                            string strLinkUrl = string.Empty;
                            string strLinkDescription = string.Empty;
                            SPFieldUrlValue strUrlValue = new SPFieldUrlValue(item["URL"].ToString());
                            strLinkUrl = strUrlValue.Url;
                            strLinkDescription = strUrlValue.Description;
                            writer.Write("<Tr>");
                            writer.Write("<Td width='5'>");
                            writer.Write(k);
                            writer.Write("</Td>");
                            writer.Write("<Td>");
                            writer.Write("<a href='" + strLinkUrl + "' target='_blank' style='font-size:x-small;color:Navy;text-Decoration:None;'>" + strLinkDescription + "</a>");
                            writer.Write("</Td>");
                            writer.Write("</Tr>");
                            writer.Write("<Tr>");
                            writer.Write("<Td bgcolor='Blue' Colspan='2'>");
                            writer.Write("</Td>");
                            writer.Write("</Tr>");
                            k++;
                        }
                        writer.Write("</Table>");
                    }
                });
            }
            catch (Exception ex)
            {
                writer.Write(ex.ToString());
            }

No comments:

Post a Comment