这是我的代码,它在gridview
中显示10条记录页面for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
{
count += 1;
}
cnt = ds.Tables[0].Rows.Count;
PagedDataSource pageData = new PagedDataSource();
pageData.DataSource = ds.Tables[0].DefaultView;
pageData.AllowPaging = true;
if (PgNum < 1)
{
pageData.PageSize = 10;
}
else
{
pageData.PageSize = 10;
}
pageData.CurrentPageIndex = PgNum;
int vcnt = cnt / pageData.PageSize;
if (PgNum < 1)
{
Panel1.Visible = true;
lnkPrevious.Visible = false;
}
else if (PgNum > 0)
{
Panel1.Visible = false;
lnkPrevious.Visible = true;
}
if (PgNum == vcnt)
{
lnkNext.Visible = false;
}
else if (PgNum < vcnt)
{
lnkNext.Visible = true;
}
repeatValues.DataSource = pageData;
repeatValues.DataBind();
我想在第一页显示10条记录,在第二页显示20条记录。任何帮助,将不胜感激。谢谢
答案 0 :(得分:0)
答案 1 :(得分:0)
在设计中将默认页面大小设置为10。
<asp:GridView ID ="grid" runat ="server" AutoGenerateColumns="False" DataKeyNames="DocumentID" DataSourceID="SqlDataSource1" PageSize="10" AllowPaging ="true" OnPageIndexChanged ="grid_PageIndexChanged" >
在网格PageIndexChanged事件的代码中执行以下操作。
protected void grid_PageIndexChanged(object sender, EventArgs e)
{
var pagenum = this.grid.PageIndex;
if (pagenum + 1 > 1)
{
this.grid.PageSize = 20;
}
else
{
this.grid.PageSize = 10;
}
}
答案 2 :(得分:0)
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
PopulateData();//This is your table data method
}
}
protected void ChangePage(object sender, GridViewPageEventArgs e)
{
GridView1.PageIndex = e.NewPageIndex;
this.PopulateData();
}
它背后的另一个代码
public DataTable SelectTopRows(DataTable dt, int count)
{
DataTable dtnew = dt.Clone();
for (int i = 0; i < count; i++)
{
dtnew.ImportRow(dt.Rows[i]);
}
return dtnew ;
答案 3 :(得分:0)
如果您需要在第一页中显示10 records
,在20 records
的后续页面中显示GridView
,则解决方案将是:
在.aspx页面
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" BackColor="White" BorderColor="#3366CC" BorderStyle="None" BorderWidth="1px" CellPadding="4" DataKeyNames="CompanyID" DataSourceID="SqlDataSource1" EnableModelValidation="True" AllowPaging="true" PageSize="10"
OnPageIndexChanging="GridView1_PageIndexChanging" >
...
</asp:GridView>
在.aspx.cs页面
protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
GridView1.PageIndex = e.NewPageIndex;
if(e.NewPageIndex != 0)
GridView1.PageSize = 20;
else
GridView1.PageSize = 10;
GridView1.DataBind();
}
我希望它会有所帮助。