Saturday, 16 March 2013

GridView: Pager Property Customized

GridView Pager Property Customized - Start
User control .ASCX file:
<%@ Control Language="C#" AutoEventWireup="true" CodeFile="HomeCurrentStudentList.ascx.cs" Inherits="UserControl_CurrentStudentList" %>
Current student list.

<asp:GridView ID="studentListGridView" runat="server"
    AutoGenerateColumns="False"
    AllowPaging="True"
    EmptyDataText="No record found"
    onpageindexchanging="studentListGridView_PageIndexChanging"
    DataKeyNames="STUD_AdmissionNumber"
    EnablePersistedSelection="True" PageSize="15">
    <Columns>
        <asp:BoundField DataField="STUD_ID" HeaderText="STUD_ID"
            SortExpression="STUD_ID" Visible="False" />
        <asp:BoundField DataField="STUD_AdmissionNumber" HeaderText="Admission Number"
            SortExpression="STUD_AdmissionNumber" />
        <asp:BoundField DataField="STUD_Surname" HeaderText="Surname"
            SortExpression="STUD_Surname" />
        <asp:BoundField DataField="STUD_Forename" HeaderText="Forename"
            SortExpression="STUD_Forename" />
        <asp:BoundField DataField="STUD_Called" HeaderText="Called"
            SortExpression="STUD_Called" />
        <asp:CheckBoxField DataField="STUD_Induction" HeaderText="Induction"
            SortExpression="STUD_Induction" />
    </Columns>
    <PagerSettings FirstPageText="First page"
        LastPageText="Last page" PreviousPageText="Previous" NextPageText="Next"
        Position="TopAndBottom" PageButtonCount="20"/>
    <PagerStyle BackColor="#6699FF" />
</asp:GridView>


User control .ASCX.CS file:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class UserControl_CurrentStudentList : System.Web.UI.UserControl
{
    protected void Page_Load(object sender, EventArgs e)
    {
        //Initialy load the GridView with first page of data
        studentListGridView.DataSource = StudentList.GetAllStudent();
        // Needed to bind the data bound controls to the data source
        studentListGridView.DataBind();
    }
    protected void studentListGridView_PageIndexChanging(object sender, GridViewPageEventArgs e)
    {
        studentListGridView.PageIndex = e.NewPageIndex;
        studentListGridView.DataBind();
     
    }

  
}

GridView Pager Property Customized - End

No comments:

Post a Comment