paging in gridview get same data for all pages
<p>I had gridview which get data from database according to two event .The first from method ,the second when selected ddl.it worked well ,I made paging and when I go through paging pages I must click two click on number of page to go to this page also all pages get same data for firt page .So plaes any one help me.</p>

<pre><code>&lt;aspx&gt;

&lt;div class="div_open_CS m10 ad_mun_font"&gt;
                                &lt;table width="560" border="0" align="center" cellpadding="2" cellspacing="0"&gt;
                                    &lt;tr&gt;
                                        &lt;td class="pag_bor"&gt;
                                            &lt;table width="100%" border="0" cellspacing="0" cellpadding="0"&gt;
                                                &lt;tr&gt;
                                                    &lt;td class="Pag_toparow"&gt;
                                                        &amp;nbsp;
                                                    &lt;/td&gt;
                                                    &lt;td class="Pag_hedfont"&gt;
                                                        Dealers list
                                                    &lt;/td&gt;
                                                &lt;/tr&gt;
                                            &lt;/table&gt;
                                        &lt;/td&gt;
                                    &lt;/tr&gt;
                                    &lt;tr&gt;
                                        &lt;td class="pag_bor"&gt;
                                            &lt;table width="100%" border="0" cellspacing="0" cellpadding="0"&gt;
                                                &lt;tr&gt;
                                                    &lt;td class="ad_mun_font_h" width="100"&gt;
                                                        Select City
                                                    &lt;/td&gt;
                                                    &lt;td&gt;
                                                        &lt;asp:SqlDataSource ID="SDSGetDealerArea" runat="server" ConnectionString="&lt;%$ ConnectionStrings:ElarabyGroup %&gt;"
                                                            ProviderName="System.Data.SqlClient" SelectCommand="SELECT [AREA_ID], [AREA_ENG] FROM [DealerArea]"&gt;
                                                        &lt;/asp:SqlDataSource&gt;
                                                        &lt;%--  &lt;asp:UpdatePanel ID="UpdatePanel1" runat="server"&gt;
                                                                &lt;ContentTemplate&gt;--%&gt;
                                                        &lt;asp:DropDownList CssClass="ad_mun_font_h" ID="DDlCity" runat="server" AutoPostBack="True"
                                                            DataSourceID="SDSGetDealerArea" DataTextField="AREA_ENG" DataValueField="AREA_ID"
                                                            OnDataBound="DDlCity_DataBound" OnSelectedIndexChanged="DDlCity_SelectedIndexChanged"&gt;
                                                        &lt;/asp:DropDownList&gt;
                                                        &lt;%-- &lt;/ContentTemplate&gt;
                                                                &lt;Triggers&gt;
                                                                    &lt;asp:AsyncPostBackTrigger ControlID="DDlCity" EventName="SelectedIndexChanged" /&gt;
                                                                &lt;/Triggers&gt;
                                                            &lt;/asp:UpdatePanel&gt;--%&gt;
                                                    &lt;/td&gt;
                                                    &lt;td&gt;
                                                        &lt;asp:Label ID="LblResult" runat="server" Text="Result" Font-Bold="True" ForeColor="#006699"
                                                            Visible="false"&gt;&lt;/asp:Label&gt;
                                                    &lt;/td&gt;
                                                &lt;/tr&gt;
                                            &lt;/table&gt;
                                        &lt;/td&gt;
                                    &lt;/tr&gt;
                                    &lt;tr&gt;
                                        &lt;td valign="top" class="tm10 rm10"&gt;
                                            &lt;asp:GridView ID="GridView1" runat="server" AllowPaging="True" AllowSorting="True"
                                                AutoGenerateColumns="False" BackColor="White" BorderColor="#999999" BorderStyle="None"
                                                CellPadding="3" DataKeyNames="DEALER_ID,LOC_ID,CAT_ID,AREA_ID" CellSpacing="3"
                                                GridLines="Horizontal" Width="510px" BorderWidth="1px" OnPageIndexChanging="GridView1_PageIndexChanging"&gt;
                                                &lt;FooterStyle BackColor="#CCCCCC" ForeColor="Black" /&gt;
                                                &lt;RowStyle BackColor="#EEEEEE" ForeColor="Black" /&gt;
                                                &lt;Columns&gt;
                                                    &lt;asp:TemplateField HeaderText="Name" SortExpression="NAME_ENG"&gt;
                                                        &lt;ItemTemplate&gt;
                                                            &lt;asp:Label ID="Label1" runat="server" Text='&lt;%# Bind("NAME_ENG") %&gt;'&gt;&lt;/asp:Label&gt;
                                                        &lt;/ItemTemplate&gt;
                                                        &lt;EditItemTemplate&gt;
                                                            &lt;asp:TextBox ID="TextBox1" runat="server" Text='&lt;%# Bind("NAME_ENG") %&gt;'&gt;&lt;/asp:TextBox&gt;
                                                        &lt;/EditItemTemplate&gt;
                                                    &lt;/asp:TemplateField&gt;
                                                    &lt;asp:TemplateField HeaderText="Address" SortExpression="ADR_ENG"&gt;
                                                        &lt;ItemTemplate&gt;
                                                            &lt;asp:Label ID="Label2" runat="server" Text='&lt;%# Bind("ADR_ENG") %&gt;'&gt;&lt;/asp:Label&gt;
                                                        &lt;/ItemTemplate&gt;
                                                        &lt;EditItemTemplate&gt;
                                                            &lt;asp:TextBox ID="TextBox2" runat="server" Text='&lt;%# Bind("ADR_ENG") %&gt;'&gt;&lt;/asp:TextBox&gt;
                                                        &lt;/EditItemTemplate&gt;
                                                    &lt;/asp:TemplateField&gt;
                                                    &lt;asp:TemplateField HeaderText="Telephone" SortExpression="TEL_ENG"&gt;
                                                        &lt;ItemTemplate&gt;
                                                            &lt;asp:Label ID="Label3" runat="server" Text='&lt;%# Bind("TEL_ENG") %&gt;'&gt;&lt;/asp:Label&gt;
                                                        &lt;/ItemTemplate&gt;
                                                        &lt;EditItemTemplate&gt;
                                                            &lt;asp:TextBox ID="TextBox3" runat="server" Text='&lt;%# Bind("TEL_ENG") %&gt;'&gt;&lt;/asp:TextBox&gt;
                                                        &lt;/EditItemTemplate&gt;
                                                    &lt;/asp:TemplateField&gt;
                                                    &lt;asp:TemplateField HeaderText="Mobile" SortExpression="TEL_ARA"&gt;
                                                        &lt;ItemTemplate&gt;
                                                            &lt;asp:Label ID="Label4" runat="server" Text='&lt;%# Bind("TEL_ARA") %&gt;'&gt;&lt;/asp:Label&gt;
                                                        &lt;/ItemTemplate&gt;
                                                        &lt;EditItemTemplate&gt;
                                                            &lt;asp:TextBox ID="TextBox4" runat="server" Text='&lt;%# Bind("TEL_ARA") %&gt;'&gt;&lt;/asp:TextBox&gt;
                                                        &lt;/EditItemTemplate&gt;
                                                    &lt;/asp:TemplateField&gt;
                                                    &lt;asp:TemplateField HeaderText="Location" SortExpression="LOC_ENG"&gt;
                                                        &lt;ItemTemplate&gt;
                                                            &lt;asp:Label ID="Label5" runat="server" Text='&lt;%# Bind("LOC_ENG") %&gt;'&gt;&lt;/asp:Label&gt;
                                                        &lt;/ItemTemplate&gt;
                                                        &lt;EditItemTemplate&gt;
                                                            &lt;asp:TextBox ID="TextBox5" runat="server" Text='&lt;%# Bind("LOC_ENG") %&gt;'&gt;&lt;/asp:TextBox&gt;
                                                        &lt;/EditItemTemplate&gt;
                                                    &lt;/asp:TemplateField&gt;
                                                    &lt;asp:TemplateField HeaderText="Category" SortExpression="CAT_NAME"&gt;
                                                        &lt;ItemTemplate&gt;
                                                            &lt;asp:Label ID="Label6" runat="server" Text='&lt;%# Bind("CAT_NAME") %&gt;'&gt;&lt;/asp:Label&gt;
                                                        &lt;/ItemTemplate&gt;
                                                        &lt;EditItemTemplate&gt;
                                                            &lt;asp:TextBox ID="TextBox6" runat="server" Text='&lt;%# Bind("CAT_NAME") %&gt;'&gt;&lt;/asp:TextBox&gt;
                                                        &lt;/EditItemTemplate&gt;
                                                    &lt;/asp:TemplateField&gt;
                                                    &lt;asp:TemplateField HeaderText="Area" SortExpression="AREA_ENG"&gt;
                                                        &lt;ItemTemplate&gt;
                                                            &lt;asp:Label ID="Label7" runat="server" Text='&lt;%# Bind("AREA_ENG") %&gt;'&gt;&lt;/asp:Label&gt;
                                                        &lt;/ItemTemplate&gt;
                                                        &lt;EditItemTemplate&gt;
                                                            &lt;asp:TextBox ID="TextBox7" runat="server" Text='&lt;%# Bind("AREA_ENG") %&gt;'&gt;&lt;/asp:TextBox&gt;
                                                        &lt;/EditItemTemplate&gt;
                                                    &lt;/asp:TemplateField&gt;
                                                &lt;/Columns&gt;
                                                &lt;PagerStyle BackColor="#999999" ForeColor="Black" HorizontalAlign="Center" /&gt;
                                                &lt;SelectedRowStyle BackColor="#008A8C" Font-Bold="True" ForeColor="White" /&gt;
                                                &lt;HeaderStyle BackColor="#000084" Font-Bold="True" ForeColor="White" /&gt;
                                                &lt;AlternatingRowStyle BackColor="#DCDCDC" /&gt;
                                            &lt;/asp:GridView&gt;
                                            &lt;asp:Panel ID="pnlModal" runat="server" Style="display: none" CssClass="modalPopup"&gt;
                                                Our Valued Customer You Are Not Registered Are You Want To Register?
                                                &lt;br /&gt;
                                                &lt;br /&gt;
                                                &lt;br /&gt;
                                                &lt;br /&gt;
                                                &lt;table id="LoginTL" runat="server" width="300" border="0" align="center" cellpadding="0"
                                                    cellspacing="2" visible="true" style="border-color: #666666"&gt;
                                                    &lt;tr&gt;
                                                        &lt;td width="80px" class="bod_d_reg_txt_p lm7"&gt;
                                                            Username :
                                                        &lt;/td&gt;
                                                        &lt;td&gt;
                                                            &lt;label&gt;
                                                                &lt;asp:TextBox ID="TxtUser" runat="server" Width="125px"&gt;&lt;/asp:TextBox&gt;
                                                            &lt;/label&gt;
                                                            &lt;asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ErrorMessage="*"
                                                                ControlToValidate="TxtUser" Display="Dynamic" SetFocusOnError="True"&gt;*&lt;/asp:RequiredFieldValidator&gt;
                                                        &lt;/td&gt;
                                                        &lt;td&gt;
                                                            &lt;table width="110" border="0" cellspacing="0" cellpadding="0"&gt;
                                                                &lt;tr&gt;
                                                                    &lt;td&gt;
                                                                        &lt;label&gt;
                                                                            &lt;asp:CheckBox ID="CBRemeber" runat="server" class="tx_s" OnCheckedChanged="CBRemeber_CheckedChanged" /&gt;
                                                                        &lt;/label&gt;
                                                                    &lt;/td&gt;
                                                                    &lt;td class="bod_d_reg_txt_w"&gt;
                                                                        Remember me
                                                                    &lt;/td&gt;
                                                                &lt;/tr&gt;
                                                            &lt;/table&gt;
                                                        &lt;/td&gt;
                                                    &lt;/tr&gt;
                                                    &lt;tr&gt;
                                                        &lt;td width="80" class="bod_d_reg_txt_p lm7"&gt;
                                                            Password :
                                                        &lt;/td&gt;
                                                        &lt;td&gt;
                                                            &lt;label&gt;
                                                                &lt;asp:TextBox ID="TXTPassword" runat="server" TextMode="Password" Width="125px"&gt;&lt;/asp:TextBox&gt;
                                                            &lt;/label&gt;
                                                            &lt;asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server" ErrorMessage="*"
                                                                ControlToValidate="TXTPassword" Display="Dynamic" SetFocusOnError="True"&gt;*&lt;/asp:RequiredFieldValidator&gt;
                                                        &lt;/td&gt;
                                                        &lt;td&gt;
                                                            &lt;asp:ImageButton ID="IBLogin" runat="server" ImageUrl="images/home-d_login.jpg" OnClick="IBLogin_Click" /&gt;
                                                        &lt;/td&gt;
                                                    &lt;/tr&gt;
                                                    &lt;tr&gt;
                                                        &lt;td&gt;
                                                        &lt;/td&gt;
                                                        &lt;td&gt;
                                                        &lt;/td&gt;
                                                        &lt;td&gt;
                                                        &lt;/td&gt;
                                                    &lt;/tr&gt;
                                                    &lt;tr&gt;
                                                        &lt;td&gt;
                                                            &lt;asp:Label ID="Label8" runat="server" CssClass="ad_mun_font" Text="result" Visible="false"&gt;&lt;/asp:Label&gt;
                                                        &lt;/td&gt;
                                                        &lt;td&gt;
                                                        &lt;/td&gt;
                                                        &lt;td&gt;
                                                        &lt;/td&gt;
                                                    &lt;/tr&gt;
                                                    &lt;tr&gt;
                                                        &lt;td&gt;
                                                            &lt;a href="Default.aspx" id="btnClose" runat="server"&gt;Close&lt;/a&gt;
                                                        &lt;/td&gt;
                                                        &lt;td&gt;
                                                        &lt;/td&gt;
                                                        &lt;td&gt;
                                                            &lt;a href="Registeration.aspx" id="Register" runat="server"&gt;Register&lt;/a&gt;
                                                        &lt;/td&gt;
                                                    &lt;/tr&gt;
                                                &lt;/table&gt;
                                                &lt;br /&gt;
                                            &lt;/asp:Panel&gt;
                                            &lt;cc1:ModalPopupExtender TargetControlID="btnYes" ID="pnlModal_ModalPopupExtender"
                                                runat="server" Enabled="True" BackgroundCssClass="modalBackground" PopupControlID="pnlModal"
                                                CancelControlID="btnYes" DropShadow="true"&gt;
                                            &lt;/cc1:ModalPopupExtender&gt;
                                            &lt;asp:HiddenField ID="btnYes" runat="server" /&gt;
                                        &lt;/td&gt;
                                    &lt;/tr&gt;
                                &lt;/table&gt;
                            &lt;/div&gt;
</code></pre>

<p><strong></strong></p>

<pre><code> protected void Page_Load(object sender, EventArgs e)
    {

        if (!IsPostBack)
        {


           BindGridFunction();
        }


    }


    private void BindGridFunction()
    {

        DataTable DT = new DataTable();
        using (SqlConnection con = Connection.GetConnection())
        {
            SqlCommand Com = new SqlCommand();
            if (DDlCity.SelectedIndex &lt; 0)
            {
                Com = new SqlCommand("GetDealers", con);
                Com.CommandType = CommandType.StoredProcedure;
                SqlDataAdapter DA = new SqlDataAdapter(Com);
                DA.Fill(DT);
                GridView1.DataSource = DT;
                GridView1.DataBind();
            }
            else
            {
                Com = new SqlCommand("GetDealersByArea", con);
                Com.CommandType = CommandType.StoredProcedure;
                Com.Parameters.Add(Parameter.NewNVarChar("@AREA_ENG", DDlCity.SelectedItem.Text));
                SqlDataAdapter DA = new SqlDataAdapter(Com);
                DA.Fill(DT);
                GridView1.DataSource = DT;
                GridView1.DataBind();
            }



        }
    }



    protected void DDlCity_SelectedIndexChanged(object sender, EventArgs e)
    {
        BindGridFunction();


    }


    protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
    {
        GridView1.PageIndex = e.NewPageIndex;
    }
}
</code></pre>
