注册 登录
编程论坛 ASP.NET技术论坛

如何解决:激发了未处理的事件“Sorting”?谢谢!

foshan 发布于 2007-03-19 12:45, 5104 次点击

小弟 在后期绑定数据源给GridView控件 ,GridView控件在视图中的智能标记中通过编辑列给相关的列进行了设置,并设置了一列可以进行排序的。但在点击该列进行排序时出现错误提示:激发了未处理的事件“Sorting”。如何解决这个问题啊?谢谢!

“/showbaobiao”应用程序中的服务器错误。
--------------------------------------------------------------------------------

GridView“GridView2”激发了未处理的事件“Sorting”。
说明: 执行当前 Web 请求期间,出现未处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。

异常详细信息: System.Web.HttpException: GridView“GridView2”激发了未处理的事件“Sorting”。

源错误:

执行当前 Web 请求期间生成了未处理的异常。可以使用下面的异常堆栈跟踪信息确定有关异常原因和发生位置的信息。

堆栈跟踪:


[HttpException (0x80004005): GridView“GridView2”激发了未处理的事件“Sorting”。]
System.Web.UI.WebControls.GridView.OnSorting(GridViewSortEventArgs e) +1427611
System.Web.UI.WebControls.GridView.HandleSort(String sortExpression, SortDirection sortDirection) +76
System.Web.UI.WebControls.GridView.HandleSort(String sortExpression) +70
System.Web.UI.WebControls.GridView.HandleEvent(EventArgs e, Boolean causesValidation, String validationGroup) +552
System.Web.UI.WebControls.GridView.RaisePostBackEvent(String eventArgument) +199
System.Web.UI.WebControls.GridView.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +7
System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +11
System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +174
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +5102


--------------------------------------------------------------------------------
版本信息: Microsoft .NET Framework 版本:2.0.50727.42; ASP.NET 版本:2.0.50727.210

[此贴子已经被作者于2007-3-19 12:47:01编辑过]

14 回复
#2
cyyu_ryh2007-03-19 13:08
该事件中没有写任何东西吗?
#3
冰镇柠檬汁儿2007-03-19 13:18
在html代码里把Sorting这个响应事件去掉,用搜索,找到就删掉,你试试
#4
foshan2007-03-19 13:25
在html代码里把Sorting这个响应事件去掉,那岂不是点击该列,不会再排序了???
#5
foshan2007-03-19 13:27
以下是引用cyyu_ryh在2007-3-19 13:08:55的发言:
该事件中没有写任何东西吗?

什么也没有,只得:
protected void GridView2_Sorted(object sender, EventArgs e)
{
 }
是不是如果采用后期绑定数据源与前期绑定数据源,其设置排序的方法不同???

#6
bygg2007-03-19 16:05
是少了Sorting事件..
#7
foshan2007-03-19 16:35
搞定了,但是在采用 后期绑定数据源给GridView控件 后,排序不起作用,何解??
#8
冰镇柠檬汁儿2007-03-19 16:50
那就在后台代码里实现Sorting事件啊
#9
foshan2007-03-20 08:33
以下代码,在排序时,还是没有反应,什么回事啊???

protected void GridView2_Sorting(object sender, GridViewSortEventArgs e)
{
SqlConnection conn1 = new SqlConnection("data source=(local);database=****;user=****; password=********"); //创建连接对象,并指明要连接的数据库名称、用户名、用户密码
SqlDataAdapter da1 = new SqlDataAdapter(); //创建数据适配器
DataSet ds1 = new DataSet(); //创建DataSet(数据集)
//适配器对象的查询命令
SqlCommand cmdSel = new SqlCommand("select ID,MYDATE,WJLX,WJLJ from baobiao", conn1); //创建DataAdapter(数据适配器)
da1.SelectCommand = cmdSel;
da1.Fill(ds1, "baobiao"); //使用数据适配器填充数据集
e.SortExpression = "WJLX"; //按WJLX字段进行排序
GridView2.DataSource = ds1.Tables["baobiao"];
GridView2.DataBind();
}
#10
chenjin1452007-03-20 09:47
GridView2.Sort("WJLX", SortDirection.Ascending);

#11
冰镇柠檬汁儿2007-03-20 09:59
这样的排序最好是让数据库来做,用GridView的方法应该是会影响速度的
#12
foshan2007-03-20 10:55

出现如下错误,如何解决???

using System;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.IO; //提供用于向文件读写数据的类(本程序要用到删除文件)

public partial class Default2 : System.Web.UI.Page
{
public static DataSet ds1 = null; //将数据集 ds1 为全局变量
protected void Page_Load(object sender, EventArgs e)
{
SqlConnection conn1 = new SqlConnection("data source=(local);database=****;user=****; password=********"); //创建连接对象,并指明要连接的数据库名称、用户名、用户密码
SqlDataAdapter da1 = new SqlDataAdapter(); //创建数据适配器
DataSet ds1 = new DataSet(); //创建DataSet(数据集)
//适配器对象的查询命令
SqlCommand cmdSel = new SqlCommand("select ID,MYDATE,WJLX,WJLJ from baobiao", conn1); //创建DataAdapter(数据适配器)
da1.SelectCommand = cmdSel;
da1.Fill(ds1, "baobiao"); //使用数据适配器填充数据集
GridView2.DataSource = ds1.Tables["baobiao"]; //指定数据源
GridView2.DataBind(); //绑定、显示数据
}
protected void GridView2_Sorting(object sender, GridViewSortEventArgs e)
{
GridView2.Sort("WJLX", SortDirection.Ascending);//按WJLX字段进行排序
GridView2.DataSource = ds1.Tables["baobiao"];
GridView2.DataBind();
}
}

只有本站会员才能查看附件,请 登录

#13
chenjin1452007-03-20 10:57
sort会激发sorting事件的

你写那里面干嘛

写在点击连接事件中啊
#14
foshan2007-03-20 11:21
没办法,太菜了!

GridView2.Sort("WJLX", SortDirection.Ascending); 放在 Page_Load 事件中,排序时还是没有反应。

public partial class Default2 : System.Web.UI.Page
{
public static DataSet ds1 = null; //将数据集 ds1 为全局变量
protected void Page_Load(object sender, EventArgs e)
{
SqlConnection conn1 = new SqlConnection("data source=(local);database=****;user=****; password=********"); //创建连接对象,并指明要连接的数据库名称、用户名、用户密码
SqlDataAdapter da1 = new SqlDataAdapter(); //创建数据适配器
DataSet ds1 = new DataSet(); //创建DataSet(数据集)
//适配器对象的查询命令
SqlCommand cmdSel = new SqlCommand("select ID,MYDATE,WJLX,WJLJ from baobiao", conn1); //创建DataAdapter(数据适配器)
da1.SelectCommand = cmdSel;
da1.Fill(ds1, "baobiao"); //使用数据适配器填充数据集
GridView2.DataSource = ds1.Tables["baobiao"]; //指定数据源
GridView2.DataBind(); //绑定、显示数据
GridView2.Sort("WJLX", SortDirection.Ascending);//按WJLX字段进行排序
}
protected void GridView2_Sorting(object sender, GridViewSortEventArgs e)
{
//GridView2.DataSource = ds1.Tables["baobiao"];
//GridView2.DataBind();
}
}
#15
chenjin1452007-03-20 11:23
你都DataBind掉了  排序后又没再显示
1