Click here to Skip to main content
15,914,323 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i want to provide custom paging in grid view...

ASP.NET
<asp:GridView ID="gvFirst" runat="server" AutoGenerateColumns="false"
            AllowPaging="true"
            ondatabound="gvFirst_DataBound" >
            <Columns>
                <asp:BoundField DataField="ID" HeaderText="ProductID"/>
                <asp:BoundField DataField="Name" HeaderText="ProductName" />
            </Columns>
            <PagerTemplate>
                <asp:Panel ID="pnlPager" runat="server">
                </asp:Panel>
            </PagerTemplate>
        </asp:GridView>


If i create button here and bind click event then it is fire...but problem is this evet occur for each row bind with grid

C#
protected void gvFirst_RowCreated(object sender, GridViewRowEventArgs e)
       {
           if (e.Row.RowType == DataControlRowType.Pager)
           {
               Panel pnPager = e.Row.FindControl("pnlPager") as Panel;
               if (pnPager != null)
               {
                   Button btnFirst = new Button();
                   btnFirst.Text = "1";
                   btnFirst.Click += new EventHandler(btnFirst_Click);
                   pnPager.Controls.Add(btnFirst);
               }
           }
       }


If i create button here and bind click event then it is not fire...this event fire after all the rows bind to grid..so it will occur only once..

C#
protected void gvFirst_DataBound(object sender, EventArgs e)
        {
            GridViewRow gvRow = gvFirst.BottomPagerRow;
            if (gvRow != null)
            {
                Panel pnPager = gvRow.FindControl("pnlPager") as Panel;
                if (pnPager != null)
                {
                    Button btnFirst = new Button();
                    btnFirst.Text = "1";
                    btnFirst.Click += new EventHandler(btnFirst_Click);
                    pnPager.Controls.Add(btnFirst);
                }
            }
        }

        void btnFirst_Click(object sender, EventArgs e)
        {
            using (_NorthWindDataContext = new NorthWindDataContext())
            {
                var ProductInformation = from p in _NorthWindDataContext.Products
                                         select new
                                         {
                                             ID = p.ProductID,
                                             Name = p.ProductName
                                         };
                gvFirst.DataSource = ProductInformation.Skip(5).Take(5);
                gvFirst.DataBind();
            }
        }


pls help me to understand this...
**Another problem which i am facing is**...
i want to provide custom paging , now i have set page size to 5 and i am fetching 5 record from query so my grid pager is not display please help me out of this...
Posted
Updated 17-Sep-11 12:15pm
v2
Comments
Herman<T>.Instance 18-Sep-11 8:22am    
make sure you load the full data in stead of saying select top 5

For Paging you can check this [^]
 
Share this answer
 
HAve u added PageIndexchanged event ?

protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
GridView1.PageIndex = e.NewPageIndex;
}
try this ,
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900