title: PagerTemplate in gridview not working properly
body: <p>I am not getting the point why this is happening.</p>
  
  <p>I have a Gridview, inside that I have implemented a <strong>pagerTemplate</strong>. It is showing me the correct records which are coming from the database.</p>
  
  <p>First of All, I took the logic of implementing the gridview pager part from <a href="http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.gridview.pagecount(v=vs.110).aspx">here</a>. And I implemented the same as described their.</p>
  
  <p>Now the scenario which I came up with is that, When I change the dropdown selection, my gridview gets postback and all the <code>Row</code> of the grid gets disturbed. I dont know why this is happening. </p>
  
  <p>See the code which I implemented:-</p>
  
  <pre><code>&lt;asp:GridView ID="grdCSRPageData" runat="server" Width="100%" border="1" Style="border: 1px solid #E5E5E5;" CellPadding="3"
              AutoGenerateColumns="False" OnDataBound="grdCSRPageData_DataBound" AllowPaging="true" CssClass="hoverTable" EmptyDataText="No Records Found"
              OnPageIndexChanging="grdCSRPageData_PageIndexChanging" DataKeyNames="Id" OnRowDeleting="grdCSRPageData_RowDeleting"
              PageSize="4" ShowFooter="true" OnRowEditing="grdCSRPageData_RowEditing" OnRowUpdating="grdCSRPageData_RowUpdating"
              OnRowCancelingEdit="grdCSRPageData_RowCancelingEdit"&gt;
              &lt;AlternatingRowStyle CssClass="k-alt" BackColor="#f5f5f5" /&gt;
              &lt;Columns&gt;
                  &lt;asp:TemplateField HeaderText="Select" HeaderStyle-Width="5%" HeaderStyle-CssClass="k-grid td"&gt;
                      &lt;ItemTemplate&gt;
                          &lt;asp:CheckBox ID="chkSelect" runat="server" AutoPostBack="false" /&gt;
                      &lt;/ItemTemplate&gt;
                  &lt;/asp:TemplateField&gt;
                  &lt;asp:BoundField DataField="page_title" HeaderText="Page Title" ItemStyle-Width="30" HeaderStyle-CssClass="k-grid td" /&gt;
                  &lt;asp:BoundField DataField="page_description" HeaderText="Page Description" ItemStyle-Width="30" HeaderStyle-CssClass="k-grid td" /&gt;
                  &lt;asp:BoundField DataField="meta_title" HeaderText="Meta Title" ItemStyle-Width="30" HeaderStyle-CssClass="k-grid td" /&gt;
                  &lt;asp:BoundField DataField="meta_keywords" HeaderText="Meta Keywords" ItemStyle-Width="30" HeaderStyle-CssClass="k-grid td" /&gt;
                  &lt;asp:BoundField DataField="meta_description" HeaderText="Meta Description" ItemStyle-Width="30" HeaderStyle-CssClass="k-grid td" /&gt;
                  &lt;asp:BoundField DataField="Active" HeaderText="Active" ItemStyle-Width="30" HeaderStyle-CssClass="k-grid td" /&gt;
                  &lt;asp:TemplateField HeaderText="Action" HeaderStyle-Width="15%" HeaderStyle-CssClass="k-grid td"&gt;
                      &lt;ItemTemplate&gt;
                          &lt;asp:ImageButton ID="btnDelete" AlternateText="Delete" ImageUrl="~/images/delete.png" runat="server" Width="15" Height="15" CommandName="Delete" CommandArgument='&lt;%# Eval("Id") %&gt;' CausesValidation="false" OnClientClick="return confirm('Are you sure you want to delete this record?')" /&gt;
                      &lt;/ItemTemplate&gt;
                  &lt;/asp:TemplateField&gt;
                  &lt;asp:CommandField ButtonType="Image" ItemStyle-Width="15" EditImageUrl="~/images/edit.png" ShowEditButton="True" ControlStyle-Width="15" ControlStyle-Height="15" CancelImageUrl="~/images/close.png" UpdateImageUrl="~/images/update.png"&gt;
                      &lt;ControlStyle Height="20px" Width="20px"&gt;&lt;/ControlStyle&gt;
                  &lt;/asp:CommandField&gt;
              &lt;/Columns&gt;
               &lt;pagerstyle /&gt;
          &lt;pagerTemplate&gt;
              &lt;table style="width:100%"&gt;
                  &lt;tr&gt;
                      &lt;td&gt;
                          &lt;asp:label id="MessageLabel" Text="Select a page:" runat="server"/&gt;
              &lt;asp:dropdownlist id="PageDropDownList" AutoPostBack="true" OnSelectedIndexChanged="PageDropDownList_SelectedIndexChanged" 
                runat="server"/&gt;
  
                          &lt;td style="width:70%; text-align:right"&gt;
                          &lt;asp:label id="CurrentPageLabel"  runat="server"/&gt;
            &lt;/td&gt;
  
                      &lt;/td&gt;
                  &lt;/tr&gt;
              &lt;/table&gt;
          &lt;/pagerTemplate&gt;
          &lt;/asp:GridView&gt;
  </code></pre>
  
  <p>The code is added with <code>PagerTemplate</code>. Also see my code behind as given their:-
  Cs Code for the PagerTemplate:-</p>
  
  <pre><code>protected void grdCSRPageData_DataBound(object sender, EventArgs e)
      {
          GridViewRow pagerRow = grdCSRPageData.BottomPagerRow;
          DropDownList pageList = (DropDownList)pagerRow.Cells[0].FindControl("PageDropDownList");
          Label pageLabel = (Label)pagerRow.Cells[0].FindControl("CurrentPageLabel");
          if (pageList != null)
          {
              for (int i = 0; i &lt; grdCSRPageData.PageCount; i++)
              {
                  int pageNumber = i + 1;
                  ListItem item = new ListItem(pageNumber.ToString());
                  if (i == grdCSRPageData.PageIndex)
                  {
                      item.Selected = true;
                  }
                  pageList.Items.Add(item);
              }
          }
          if (pageLabel != null)
          {
              int currentPage = grdCSRPageData.PageIndex + 1;
              pageLabel.Text = "Page " + currentPage.ToString() +
                " of " + grdCSRPageData.PageCount.ToString();
          }
  }
  
   protected void PageDropDownList_SelectedIndexChanged(object sender, EventArgs e)
      {
          GridViewRow pagerRow = grdCSRPageData.BottomPagerRow;
          DropDownList pagelist = (DropDownList)pagerRow.Cells[0].FindControl("PageDropDownList");
          grdCSRPageData.PageIndex = pagelist.SelectedIndex;
      }
  </code></pre>
  
  <p>Please help. Any help would be appreciable</p>