我已经尝试使用radiobuttonlist让用户选择他/她是要将当前页面的gridview还是整个gridview导出到Excel表格,但只有当前页面的工作在哪里导出整个gridview到excel工作表,它只显示标题行。这里有什么问题,是否与radiobuttonlist的selectedindex有关?如何将gridview导出为带分页的excel表格
protected void btnExport_Click(object sender, EventArgs e)
{
if (this.RadioButtonList1.SelectedIndex == 1)
{
// the user wants all rows in the current page, set pagesize and rebind
this.GridView1.PageSize = 10;
this.GridView1.DataBind();
}
else if (this.RadioButtonList1.SelectedIndex == 2)
{
// the user wants all rows exported, have to turn off paging and rebind
this.GridView1.AllowPaging = false;
this.GridView1.DataBind();
}
GridViewExportUtil.Export("ContactsInformation.xls", this.GridView1);
}
我可能是错的,但是当你分配'PageSize'到某一值时,是不是真正的分页这只是说让我在网10个项目,但不能说GET只有10次毫秒从例如您的数据库并重新绑定这些数据。现在你的'this.GridView1.PageSize = 10; this.GridView1.DataBind();'不要说GridView显示所有现有的10个项目,如果你想做这个工作,你需要编写从DB分页的方法。请纠正我,如果我错了 – harry180 2012-08-17 06:26:57