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 12, 2013

Binding Data to Asp.Net Bulleted List without a Single line of Loop using SharePoint Data



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="BulletedListUserControl.ascx.cs" Inherits="BulletedList.BulletedList.BulletedListUserControl" %>
<style type="text/css">
.ContentClass
{
    background-color:Green;
    color:White;
    font-weight:bold;
    font-size:15px;
    font-family:Calibri;
}
</style>
<asp:BulletedList ID="blCountry" runat="server" DataValueField="ID" DataTextField="Title" CssClass="ContentClass"></asp:BulletedList>
Ascx.cs
public void getData()
        {
            SPSecurity.RunWithElevatedPrivileges(delegate()
            {
                SPQuery sQuery = new SPQuery();
                sQuery.Query = "<OrderBy><FieldRef Name=\"Title\" /></OrderBy>";
                SPListItemCollection myColl = SPContext.Current.Web.Lists["lst_Country"].GetItems(sQuery);
                if (myColl.Count > 0)
                {
                    blCountry.DataSource = myColl.GetDataTable();
                    blCountry.DataBind();
                }
            });
        }

No comments:

Post a Comment