Raju  Nair

Raju Nair

  • NA
  • 8
  • 3k

Pagination Not Working On GridView

May 4 2013 7:16 AM

  I have a griview which contains label template field.  The label values are filled during the RowDataBound. When I do pagination except this template field , all  are paginated. I think, when do pagination, each time the label template field are filled on RowDataBound.
Now I am not able to do pagination. Please help
This is my Code
    <asp:UpdatePanel ID="UpdatePanel1" runat="server">
                <ContentTemplate>
                    <asp:GridView ID="GridView1" runat="server" AllowPaging="True" BackColor="White" BorderColor="#CCCCCC" BorderStyle="None" BorderWidth="1px" CellPadding="3" OnDataBound="GridView1_DataBound" OnPageIndexChanging="GridView1_PageIndexChanging1" OnRowDataBound="GridView1_RowDataBound1" PageSize="3">
                        <Columns>
                            <asp:TemplateField HeaderText="First Row">
                                <ItemTemplate>
                                    <asp:Label ID="Label1" runat="server">Text</asp:Label>
                                </ItemTemplate>
                            </asp:TemplateField>
                        </Columns>
                        <FooterStyle BackColor="White" ForeColor="#000066" />
                        <HeaderStyle BackColor="#006699" Font-Bold="True" ForeColor="White" />
                        <PagerStyle BackColor="White" ForeColor="#000066" HorizontalAlign="Left" />
                        <RowStyle ForeColor="#000066" />
                        <SelectedRowStyle BackColor="#669999" Font-Bold="True" ForeColor="White" />
                        <SortedAscendingCellStyle BackColor="#F1F1F1" />
                        <SortedAscendingHeaderStyle BackColor="#007DBB" />
                        <SortedDescendingCellStyle BackColor="#CAC9C9" />
                        <SortedDescendingHeaderStyle BackColor="#00547E" />
                    </asp:GridView>
                </ContentTemplate>
            </asp:UpdatePanel>
 
GridView.cs
protected void Page_Load(object sender, EventArgs e)
        {
            Getdata();
        }
       
        public void Getdata()
        {
            SqlConnection con = new SqlConnection("Data Source=CMH-SOSQL\\SQ1;Initial Catalog=RPT2020_DEV;Integrated Security=True");
            con.Open();
            string qry = "use PID2020_DEV select * from batch_void_rsn_cd";
            SqlDataAdapter da = new SqlDataAdapter(qry, con);
            DataTable dt = new DataTable();
            da.Fill(dt);
            GridView1.DataSource = dt;
            GridView1.DataBind();   
        }
        protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                GridView1.Columns[0].HeaderText = "First Row";
                Label lblKey = (Label)e.Row.FindControl("Label1");
                lblKey.Text = e.Row.RowIndex.ToString();
            }
        }
        protected void GridView1_DataBound(object sender, EventArgs e)
        {
           
        }
        protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
        {
            GridView1.PageIndex = e.NewPageIndex;
            Getdata();
        }

Answers (1)