?
Solved

gridview paging not displaying second page.

Posted on 2012-08-11
3
Medium Priority
?
1,127 Views
Last Modified: 2012-08-12
Hi,
I am using below mentioned code to display data into gridview. it is showing data of first page excellent. When I clicked on 2 page or any other page the gridview disappear to the web page and webpage blank.
Please help me where I am doing wrong/

 <asp:GridView ID="Invoicing" runat="server" AutoGenerateColumns="False"
        HeaderStyle-Font-Size="Medium" HeaderStyle-Font-Italic="true" CellPadding="1"
        ForeColor="#333333" GridLines="None" Width="908px"
        AllowPaging="True" PageSize="12" AllowSorting="True" EnableSortingAndPagingCallbacks="True"
        OnPageIndexChanging="Invoicing_PageIndexChanging" >       
        <AlternatingRowStyle BackColor="White" ForeColor="#284775" />


 public partial class InvPage : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            loadGrid();
        }
        SqlConnection con;
        SqlCommand cmd;
        DataSet ds;
        SqlDataAdapter da;
                   
        private void loadGrid()
        {
             string values = "Select sno=Row_number() Over (Order by InvNo,Date), Date, InvNo, Amt=Sum(Amt), CoCom=Sum(Isnull(CoCom,0)), MkCom=Sum(Isnull(MkCom,0)), NPV=Sum(NetPurchasedValue), FreeStock from tempp Where FreeStock='0' Group by Date, InvNo, FreeStock Order by InvNo,Date";
               
            using (con = new SqlConnection(ConfigurationManager.ConnectionStrings["DLICCBPL"].ConnectionString))
            {
                cmd = new SqlCommand(values,con);
                con.Open();                
                ds = new DataSet();
                da = new SqlDataAdapter(cmd);
                da.Fill(ds,"bb");
                Invoicing.DataSource = ds;
                Invoicing.DataMember = "bb";                
                Invoicing.DataBind();

               
                con.Close();
               
            }
        }

        protected void Invoicing_PageIndexChanging(Object sender, GridViewPageEventArgs e)
        {
            Invoicing.PageIndex = e.NewPageIndex;
            Invoicing.DataBind();
            //((GridView)sender).PageIndex = e.NewPageIndex;

           
        }
       

    }
0
Comment
Question by:Mehram
  • 2
3 Comments
 

Author Comment

by:Mehram
ID: 38284279
<PagerSettings FirstPageText="First" LastPageText="Last"
            Mode="NumericFirstLast" />
0
 
LVL 20

Accepted Solution

by:
informaniac earned 2000 total points
ID: 38284908
By any chance you have disabled the Viewstate of the page?

How many records does the query return?

Please try this code.

protected void Invoicing_PageIndexChanging(Object sender, GridViewPageEventArgs e)
        {
            Invoicing.PageIndex = e.NewPageIndex;
            loadGrid();
            
        }

Open in new window

0
 

Author Comment

by:Mehram
ID: 38284967
Sir, I am asking another question related to gridview to show data on label click to load data accordingly into the gridview. please keep online to assist me.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
As many of you are aware about Scanpst.exe utility which is owned by Microsoft itself to repair inaccessible or damaged PST files, but the question is do you really think Scanpst.exe is capable to repair all sorts of PST related corruption issues?
Suggested Courses
Course of the Month17 days, 1 hour left to enroll

862 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question