![](/img/trans.png)
[英]The GridView fired event PageIndexChanging which wasn't handled
[英]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();
}
}
您處理了錯誤的事件,將其更改為PageIndexChanging
。 (並且您需要將其連接到aspx代碼中)
protected void grid_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
grid.PageIndex = e.NewPageIndex;
grid.DataBind();
}
並且您需要在頁面加載中用if(!Page.IsPostback){//do binding }
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.