NotSupportedException 未处理(gridview C#)
我正在尝试在网格视图中显示我的数据。 它工作正常,直到 . 。 。 。 。 我想做分页(每页20个数据),它会导致错误 NotSupportedException was unhandled 。
我该如何解决这个问题?
这是我的代码。 我也将分页设置为true。
public void bindGV()
{
string strCon = Database.GetConStr();
SqlConnection sqlCon = new SqlConnection(strCon);
SqlCommand sqlCommand = new SqlCommand("select * from Account", sqlCon);
sqlCon.Open();
SqlDataReader reader = sqlCommand.ExecuteReader();
StaffGV.DataSource = reader;
StaffGV.DataBind();
}
protected void GV_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
GV.PageIndex = e.NewPageIndex;
bindGV();
}
该错误来自 GV_PageIndex。
I am trying to display my data in a gridview.
It works fine, until . . . . .
I want to do paging (20 data per page), it causes an error NotSupportedException was unhandled .
How do i solve this?
This is my code.
I also have set paging to true.
public void bindGV()
{
string strCon = Database.GetConStr();
SqlConnection sqlCon = new SqlConnection(strCon);
SqlCommand sqlCommand = new SqlCommand("select * from Account", sqlCon);
sqlCon.Open();
SqlDataReader reader = sqlCommand.ExecuteReader();
StaffGV.DataSource = reader;
StaffGV.DataBind();
}
protected void GV_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
GV.PageIndex = e.NewPageIndex;
bindGV();
}
The error comes from the GV_PageIndex.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
请从
PageIndexChanging
事件中删除代码看看会发生什么。再次阅读您的代码&这意味着 - 每次单击下一页时,您都希望从数据库中获取数据并将其绑定到数据网格。绝对不能这样做。
除了设置一些属性之外,您不需要执行任何显式操作来处理数据网格中的分页。阅读一些有关如何处理数据网格中分页的介绍教程。
Please remove the code from the
PageIndexChanging
event & see what happens.Read your code again & it implies that - on every click of the next page, you would want to fetch the data from the database and bind it to the datagrid. This must not be done.
You don't need to do anything explicit to handle paging in datagrid, except to set a few properties. Read some intro tutorials on how to handle paging in datagrid.