You must Sign In to post a response.
  • Category: .NET

    Problem on DataGrid Paging

    The forum thread has not been reviewed by Editors yet. Readers are advised to use their best judgement before accessing this thread.
    This thread will be reviewed shortly.
    If you think this thread contain inappropriate content, please report to webmaster.
    Dear all, please help. I set the Allow Paging to ture in the DataGrid1. When I test it. Data can show up to 5 rows (I limited 5 rows per page). When I click on the ">", the DataGrid1 still show the 5 rows. In my database, there should 6 records and I am sure that the view I using is workable to show 6 rows.

    Could anyone help?


    The HTML:

    <%@ Page language="c#" Codebehind="WebForm1.aspx.cs" AutoEventWireup="false" Inherits="campusJob.WebForm1" %>
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
    <meta name="GENERATOR" Content="Microsoft Visual Studio .NET 7.1">
    <meta name="CODE_LANGUAGE" Content="C#">
    <meta name="vs_defaultClientScript" content="JavaScript">
    <meta name="vs_targetSchema" content="">
    <body MS_POSITIONING="GridLayout">
    <form id="Form1" method="post" runat="server">
    <FONT face="TimesNewRoman">
    <asp:DataGrid id="DataGrid1" style="Z-INDEX: 101; LEFT: 44px; POSITION: absolute; TOP: 16px" runat="server"
    AutoGenerateColumns="False" Width="596px" AllowPaging="True" PageSize="5">
    <asp:BoundColumn DataField="jobCode" HeaderText="Job No"></asp:BoundColumn>
    <asp:BoundColumn DataField="deptName" HeaderText="Employer"></asp:BoundColumn>
    <asp:BoundColumn DataField="positionName" HeaderText="Position"></asp:BoundColumn>

    The Server Control:
    using System;
    using System.Collections;
    using System.Configuration;
    using System.ComponentModel;
    using System.Data;
    using System.Data.SqlClient;
    using System.Drawing;
    using System.Web;
    using System.Web.SessionState;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Web.UI.HtmlControls;
    using System.Reflection;

    using log4net;
    using campusJob.sdk;

    namespace campusJob
    /// <summary>
    /// Summary description for WebForm1.
    /// </summary>
    public class WebForm1 : System.Web.UI.Page
    protected System.Web.UI.WebControls.DataGrid DataGrid1;
    private static readonly ILog Log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);

    private void Page_Load(object sender, System.EventArgs e)
    // Put user code to initialize the page here
    SqlConnection sqlCon = new SqlConnection(ConfigurationSettings.AppSettings["sqlServerConnection"]);
    DataTable dtWaitingJob = new DataTable("waitingForApproval");

    string getWaitingJobListSQL = "select * from waitingForApprovalJob_view order by creationDate asc";

    SqlDataAdapter da = new SqlDataAdapter(getWaitingJobListSQL, sqlCon);
    catch(Exception ex)
    Log.Fatal("[" + MethodBase.GetCurrentMethod().ReflectedType.Name.ToString() + "." +
    MethodBase.GetCurrentMethod().Name.ToString() + "]: " + ex.Message);
    finally { sqlCon.Close(); }

    DataGrid1.DataSource = dtWaitingJob;
  • #57298
    Write the following statment in the Datagrid1_PageIndexChanged event

    DataGrid1.CurrentPageIndex = e.NewPageIndex;

    This will change the page in the grid.

  • #57301
    Add DataGrid1_CurrentPageIndexchanged() event


    InThis way u have to Bind Data to Grid again

  • #57306
    for that u need to write below code in Datagrid_Pageindex changed even.......

    protected void Datagrd_PageIndexChanging(object sender, GridViewPageEventArgs e)
    Datagrd_PageIndex = e.NewPageIndex;
    //Bind the Datagrid here once again

    Lets Enjoy the Coding......

  • This thread is locked for new responses. Please post your comments and questions as a separate thread.
    If required, refer to the URL of this page in your new post.