Friday, 8 November 2013

SPgridviewpager Example using c#

Share it Please
Design Code:-

 <SharePoint:SPGridView ID="sgvPagersample" runat="server" AutoGenerateColumns="false" DataSourceID="objSample" AllowPaging="True" PageSize="3">
<Columns>
<asp:BoundField HeaderText="Employee ID" DataField="Title" />
<asp:BoundField HeaderText="Employee Name" DataField="EmpName" />
<asp:BoundField HeaderText="Employee Age" DataField="EmpAge" />
    <asp:BoundField HeaderText="Employee Salary" DataField="EmpSalary" />
</Columns>
</SharePoint:SPGridView>
    <asp:ObjectDataSource ID="objEmp" runat="server" SelectMethod="BindGridView"></asp:ObjectDataSource>
    <center>
    <SharePoint:SPGridViewPager id="sgvPager" runat="Server" GridViewId="sgvPagersample"></SharePoint:SPGridViewPager>
    </center>

Cs Code:-

  protected void Page_Load(object sender, EventArgs e)
        {
            objEmp.TypeName = this.GetType().AssemblyQualifiedName;
        }
        public DataTable BindGridView()
        {
            SPWeb currentWeb = SPContext.Current.Web;
            SPList lstEmployee = currentWeb.Lists["Employee"];
            SPQuery sQuery = new SPQuery();
            sQuery.Query = "<OrderBy><FieldRef Name='ID' Ascending='False' /></OrderBy>";
            SPListItemCollection myColl = lstEmployee.GetItems(sQuery);
            return myColl.GetDataTable();
        }

No comments:

Post a Comment

Followers

Follow The Author