我已经创建了一个gridview并绑定了它,我也给出了pageindexchanging事件,但是尽管数据库中有数据,但下一页仍显示空白数据文本。
protected void Page_Load(object sender, EventArgs e)
{
if(!IsPostBack)
{
BindGrid();
}
}
protected void BindGrid()
{
SqlConnection con = new SqlConnection(strcon);
con.Open();
SqlCommand cmd = new SqlCommand("usp_GetOutDetails", con);
cmd.CommandType = CommandType.StoredProcedure;
SqlDataAdapter sda = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
sda.Fill(ds);
GridView1.DataSource = ds;
GridView1.DataBind();
}
protected void Gridview1_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
GridView1.PageIndex = e.NewPageIndex;
GridView1.DataBind();
}
aspx
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"
Height="169px" Width="962px" style="margin-top: 15px" CellPadding="10"
CssClass="table table-bordered" AllowPaging="True"
OnPageIndexChanging="Gridview1_PageIndexChanging" EmptyDataText="No such record exists.!!!!" >
<Columns>
<asp:CommandField SelectText="Update" ShowSelectButton="True" />
<asp:BoundField HeaderText="SA Number" DataField="SANo" />
<asp:BoundField HeaderText="SA Date" DataField="SADate" DataFormatString="{0:dd/MM/yyyy}" />
<asp:BoundField HeaderText="Customer Code" DataField="CustomerCode" />
<asp:BoundField HeaderText="Customer Name" DataField="CustomerName" />
</Columns>
<HeaderStyle HorizontalAlign="Center" />
<PagerSettings Mode="Numeric" PageButtonCount="10" FirstPageText="First" LastPageText="Last"/>
<PagerStyle HorizontalAlign = "Left" CssClass = "GridPager" />
</asp:GridView>