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, January 17, 2013

How to bind SharePoint List Items Side by Side using HTML Div



OutPut:-


BackEnd List:-

Note:-
        If you want decrease the gap between the data mention height for div inside Data Div.
Ascx
<%@ Assembly Name="$SharePoint.Project.AssemblyFullName$" %>
<%@ Assembly Name="Microsoft.Web.CommandUI, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
<%@ Register Tagprefix="SharePoint" Namespace="Microsoft.SharePoint.WebControls" Assembly="Microsoft.SharePoint, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
<%@ Register Tagprefix="Utilities" Namespace="Microsoft.SharePoint.Utilities" Assembly="Microsoft.SharePoint, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
<%@ Register Tagprefix="asp" Namespace="System.Web.UI" Assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" %>
<%@ Import Namespace="Microsoft.SharePoint" %>
<%@ Register Tagprefix="WebPartPages" Namespace="Microsoft.SharePoint.WebPartPages" Assembly="Microsoft.SharePoint, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="DivTechniqueUserControl.ascx.cs" Inherits="DivTechnique.DivTechnique.DivTechniqueUserControl" %>
<style type="text/css">
.DataDiv
{
       float:left;
       width:25%;
       font-weight:bold;
       font-family:Calibri;
       font-size:13px;                  
}
.HeadingDiv
{
       font-weight:bold;
       font-family:Calibri;
       font-size:13px;
       color:Red;   
}
.mainDiv
{
    padding-left:50px;
}
</style>
<table width="100%" cellpadding="0" cellspacing="0">
<tr>
<td>
<asp:Panel ID="pnlArticles" runat="server"></asp:Panel>
</td>
</tr>
</table>

Ascx.cs
using System;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using Microsoft.SharePoint;
using System.Security;

namespace DivTechnique.DivTechnique
{
    public partial class DivTechniqueUserControl : UserControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            getArticlesData();
        }

        public void getArticlesData()
        {
            string strBindHTML = string.Empty;
            SPSecurity.RunWithElevatedPrivileges(delegate()
            {
                SPWeb currentWeb = SPContext.Current.Web;
                SPList lst = currentWeb.Lists["Articles"];
                SPQuery sQuery = new SPQuery();
                sQuery.Query = "<OrderBy><FieldRef Name='ID' /></OrderBy>";
                SPListItemCollection myColl = lst.GetItems(sQuery);
                strBindHTML += "<div align=\"center\" class=\"HeadingDiv\">";
                strBindHTML += "<Strong>";
                strBindHTML += "Articles";
                strBindHTML += "<Strong>";
                strBindHTML += "</div>";
                strBindHTML += "<div align=\"center\" class=\"HeadingDiv\">";
                strBindHTML += "&nbsp;";
                strBindHTML += "</div>";
                if (myColl.Count > 0)
                {
                    strBindHTML += "<div class=\"mainDiv\">";
                    foreach (SPListItem item in myColl)
                    {
                       //Data Div
                        strBindHTML += "<div  class=\"DataDiv\">";
                        strBindHTML += item.Title;
     //Space Div Where you have to mention height in order to decrease Gap's between items
                        strBindHTML += "<div style=\"height:2px;\">";
                        strBindHTML += "&nbsp;";
                        strBindHTML += "</div>";
                        strBindHTML += "</div>";
                    }
                    strBindHTML += "</div>";
                }
                else
                {
                    strBindHTML += "<div align=\"center\">";
                    strBindHTML += "No Articles Available";
                    strBindHTML += "</div>";
                }
            });
            pnlArticles.Controls.Add(new LiteralControl(strBindHTML));
        }
    }
}

No comments:

Post a Comment