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, April 02, 2013

Showing Image Loader while performing Paging in GridView

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="ImageLoadingGridViewUserControl.ascx.cs" Inherits="ImageLoadingGridView.ImageLoadingGridView.ImageLoadingGridViewUserControl" %>
<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="cc1" %>
<asp:Label ID="lblMessage" runat="server"></asp:Label>

<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:UpdateProgress ID="UpdateProgress1" runat="server" AssociatedUpdatePanelID="UpdatePanel1">
<ProgressTemplate>
<img alt="progress" src="/UserPages/Loading_Images/loading_1.gif" />         
</ProgressTemplate>
</asp:UpdateProgress>
<asp:GridView ID="dgvMovingImage" runat="server" AutoGenerateColumns="False"
        Width="100%" AllowPaging="True" CellPadding="4" EnableModelValidation="True"
        ForeColor="#333333"
        onpageindexchanging="dgvMobingImage_PageIndexChanging" PageSize="20">
    <AlternatingRowStyle BackColor="White" />
<Columns>
<asp:BoundField HeaderText="ItemID" DataField="ID" />
<asp:BoundField HeaderText="Title" DataField="Title" />
</Columns>
    <EditRowStyle BackColor="#2461BF" />
    <FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
    <HeaderStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
    <PagerSettings Mode="NextPrevious" NextPageText="Next"
        PreviousPageText="Previous" />
    <PagerStyle BackColor="#2461BF" ForeColor="White" HorizontalAlign="Center" />
    <RowStyle BackColor="#EFF3FB" />
    <SelectedRowStyle BackColor="#D1DDF1" Font-Bold="True" ForeColor="#333333" />
</asp:GridView>
</ContentTemplate>
</asp:UpdatePanel>
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 ImageLoadingGridView.ImageLoadingGridView
{
    public partial class ImageLoadingGridViewUserControl : UserControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                getData();
            }
        }

        protected void dgvMobingImage_PageIndexChanging(object sender, GridViewPageEventArgs e)
        {
            try
            {
                System.Threading.Thread.Sleep(3000);
                dgvMovingImage.PageIndex = e.NewPageIndex;
                getData();
            }
            catch (Exception Ex)
            {
                lblMessage.Text = Ex.ToString();
            }
        }

        public void getData()
        {
            try
            {
                SPSecurity.RunWithElevatedPrivileges(delegate()
                {
                    SPQuery strQuery = new SPQuery();
                    strQuery.Query = "";
                    SPListItemCollection myColl = SPContext.Current.Web.Lists["Moving Image Test"].GetItems(strQuery);
                    if (myColl.Count > 0)
                    {
                        dgvMovingImage.DataSource = myColl.GetDataTable();
                        dgvMovingImage.DataBind();
                    }
                });
            }
            catch (Exception Ex)
            {
                lblMessage.Text = Ex.ToString();
            }
        }
    }
}

No comments:

Post a Comment