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, February 16, 2012

Dynamically Building HTML Table With SharePoint List Data without using SpQuery.

try
                {
                    SPSecurity.RunWithElevatedPrivileges(delegate()
                    {
                        StringBuilder strMovieListings = new StringBuilder();
                        strMovieListings.Append("<Table width='100%' cellpadding='0' cellspacing='0'>");
                        strMovieListings.Append("<Tr>");
                        strMovieListings.Append("<Td  bgcolor='#add8e6'>");
                        strMovieListings.Append("<Strong>");
                        strMovieListings.Append("Movie Name");
                        strMovieListings.Append("</Strong>");
                        strMovieListings.Append("</Td>");
                        strMovieListings.Append("</Tr>");
                        SPWeb currentWeb = SPContext.Current.Web;
                        SPList lstMovieListings = currentWeb.Lists["Movie Listings"];
                        SPListItemCollection myColl = lstMovieListings.Items;
                        if (myColl.Count > 0)
                        {
                            foreach (SPListItem item in myColl)
                            {
                                string strTitle = string.Empty;
                                strTitle = item.Title.ToString();
                                strMovieListings.Append("<Tr>");
                                strMovieListings.Append("<Td>");
                                strMovieListings.Append(strTitle);
                                strMovieListings.Append("</Td>");
                                strMovieListings.Append("</Tr>");
                            }
                        }
                        strMovieListings.Append("</Table>");
                        writer.Write(strMovieListings);
                    });
                }
                catch (Exception ex)
                {
                    writer.Write(ex.ToString());
                }
            }

No comments:

Post a Comment