I have manually databinded my gridview , but problem is it won't show 2nd page index .... here's a chunk of code :
<asp:CheckBox ID="SARecords" OnCheckedChanged="SARecords_OnCheckedChanged" AutoPostBack="True" CssClass="tooltips" data-original-title="View all mapped phases." data-rel="tooltip" data-placement="top" runat="server"></asp:CheckBox>
<asp:UpdatePanel ID="ExistingMappedUpdatePanel" UpdateMode="Conditional" runat="server">
<ContentTemplate>
<asp:gridview ID="ExistingMappedGrid" ClientIDMode="Static" OnPageIndexChanging="ExistingMappedGrid_OnPageIndexChanging"
PagerStyle-CssClass="custompaging" runat="server" AutoGenerateColumns="False"
CssClass="table table-bordered" BackColor="White" ForeColor="Black" BorderStyle="Groove" ShowFooter="True"
DataKeyNames="Act_ID" >
<Columns>
<asp:BoundField DataField="Act_ID" HeaderText="Act_ID" ReadOnly="True" SortExpression="Act_ID" Visible="False" />
<asp:BoundField DataField="do_ID" HeaderText="do_ID" SortExpression="do_ID" Visible="False" />
<asp:BoundField DataField="Act_Code" HeaderText="Activity Code" SortExpression="Act_Code" />
<asp:BoundField DataField="Act_Seq" HeaderText="Activity Sequence" SortExpression="Act_Seq" />
<asp:BoundField DataField="Phase_Name" HeaderText="Construction Phase" SortExpression="Phase_Name" />
<asp:BoundField DataField="Act_Name" HeaderText="Activity Description / Name" SortExpression="Act_Name" />
<asp:TemplateField>
<ItemTemplate>
<asp:LinkButton ID="RemoveRow" CssClass="btn btn-blue btn-block" OnClick="RemoveRow_OnClick" runat="server" >Remove</asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
</Columns>
<FooterStyle CssClass="panel-heading" />
<PagerStyle BackColor="PaleGoldenrod" ForeColor="DarkSlateBlue" HorizontalAlign="Center" />
<HeaderStyle CssClass="customGridViewHeader" ForeColor="black"/>
</asp:gridview>
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="ExistingMappedGrid"/>
<asp:AsyncPostBackTrigger ControlID="SARecords" EventName="CheckedChanged"/>
</Triggers>
</asp:UpdatePanel>
and in code-behind i did this :
protected void SARecords_OnCheckedChanged(object sender, EventArgs e)
{
try
{
if (SARecords.Checked == false)
{
ExistingMappedGrid.DataSource = null;
ExistingMappedGrid.DataBind();
ExistingMappedUpdatePanel.Update();
}
else
{
query = "SELECT * FROM [v_ExistingMappedPhases] WHERE (([do_ID] = @do_ID))";
var cmd = new SqlCommand(query, _connection);
cmd.Parameters.AddWithValue("@do_ID", Session["do_ID"]);
var dt = new DataTable();
var da = new SqlDataAdapter(cmd);
da.Fill(dt);
ExistingMappedGrid.DataSource = dt;
ExistingMappedGrid.AllowPaging = true;
ExistingMappedGrid.PageSize = 5;
ExistingMappedGrid.DataBind();
ExistingMappedUpdatePanel.Update();
_connection.Close();
}
}
catch (Exception ex)
{
}
}
protected void ExistingMappedGrid_OnPageIndexChanging(object sender, GridViewPageEventArgs e)
{
PhasesTempGrid.PageIndex = e.NewPageIndex;
query = "SELECT * FROM [v_ExistingMappedPhases] WHERE (([do_ID] = @do_ID))";
var cmd = new SqlCommand(query, _connection);
cmd.Parameters.AddWithValue("@do_ID", Session["do_ID"]);
var dt = new DataTable();
var da = new SqlDataAdapter(cmd);
da.Fill(dt);
ExistingMappedGrid.DataSource = dt;
ExistingMappedGrid.AllowPaging = true;
ExistingMappedGrid.PageSize = 5;
ExistingMappedGrid.DataBind();
ExistingMappedUpdatePanel.Update();
_connection.Close();
PhasesTempGrid.DataBind();
ExistingMappedUpdatePanel.Update();
}