在我添加这些代码之前,我收到有关GridView触发的事件PageIndexChanging的错误,该事件未被处理,并且对于Sorting也是如此。所以我添加了这个事件代码然后我得到编译错误说,“CS1061:'ASP.serveredit_aspx'不包含'GridViewServer_PageIndexChanging'的定义,并且没有扩展方法'GridViewServer_PageIndexChanging'接受'ASP.serveredit_aspx'类型的第一个参数可以被发现”。但是我已经在C#中拥有了该事件代码。请帮忙
这是我的GridView属性代码,
<asp:GridView ID="GridViewServer" runat="server" AllowPaging="True" AllowSorting="True" OnPageIndexChanging="GridViewServer_PageIndexChanging" OnSorting="GridViewServer_Sorting" AutoGenerateColumns="False" BackColor="White" BorderColor="#CCCCCC" BorderStyle="None" BorderWidth="1px" CellPadding="3" DataKeyNames="ServerName" GridLines="None" ShowFooter="True" onrowcancelingedit="GridViewServer_RowCancelingEdit"
onrowdeleting="GridViewServer_RowDeleting" onrowediting="GridViewServer_RowEditing"
onrowupdating="GridViewServer_RowUpdating">
此活动背后的C#代码,
private string ConvertSortDirectionToSql(SortDirection sortDirection)
{
string newSortDirection = String.Empty;
switch (sortDirection)
{
case SortDirection.Ascending:
newSortDirection = "ASC";
break;
case SortDirection.Descending:
newSortDirection = "DESC";
break;
}
return newSortDirection;
}
protected void gridViewServer_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
GridViewServer.PageIndex = e.NewPageIndex;
GridViewServer.DataBind();
}
protected void gridViewServer_Sorting(object sender, GridViewSortEventArgs e)
{
DataTable dataTable = GridViewServer.DataSource as DataTable;
if (dataTable != null)
{
DataView dataView = new DataView(dataTable);
dataView.Sort = e.SortExpression + " " + ConvertSortDirectionToSql(e.SortDirection);
GridViewServer.DataSource = dataView;
GridViewServer.DataBind();
}
}
答案 0 :(得分:0)
我意识到gridViewServer_PageIndexChanging和gridViewServer_Sorting是小写的。我忘了把它搞定。