[英]The GridView 'grid' fired event PageIndexChanging which wasn't handled
public partial class WebForm2 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
string connectionString =
WebConfigurationManager.ConnectionStrings["base"].ConnectionString;
string selectSQL = "SELECT author,book FROM ListItem";
SqlConnection con = new SqlConnection(connectionString);
SqlCommand cmd = new SqlCommand(selectSQL, con);
SqlDataAdapter adapter = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
adapter.Fill(ds, "ListItem");
grid.DataSource = ds;
grid.DataBind();
}
protected void grid_PageIndexChanged(object sender, EventArgs e)
{
grid.PageIndex=e.NewPageIndex;//have a error grid.DataBind();
}
}
You have handled the wrong event, change it to PageIndexChanging
. 您处理了错误的事件,将其更改为
PageIndexChanging
。 (and you need to hook it up in the aspx code) (并且您需要将其连接到aspx代码中)
protected void grid_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
grid.PageIndex = e.NewPageIndex;
grid.DataBind();
}
And you need to surround the binding of the grid in the page load with a if(!Page.IsPostback){//do binding }
并且您需要在页面加载中用
if(!Page.IsPostback){//do binding }
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.