我一直在努力追捕一个非常令人沮丧的问题。起初,它是RowDataBound事件,在重写现在的整个gridview之后,它没有触发,它的排序事件。这次它抱怨没有为该事件注册的处理程序。这是个谎言!!!!!!!! 我已经尝试了很多东西,我现在很绝望,我真的不知道发生了什么。任何帮助都会得到极大的赞赏。
protected void ContactsSGV_Sorting2(object sender, GridViewSortEventArgs e)
{
var PLEASE_WORK = true;
}
<CC:SortableGridView runat="server" ID="ContactsSGV" Width="100%" DataKeyNames="ContactID,ContactType"
AllowPaging="True" AllowSorting="True" AutoGenerateColumns="false" OnRowDataBound="ContactsSGV_RowDataBound"
OnPageIndexChanging="ContactsSGV_PageIndexChanging" OnSorting="ContactsSGV_Sorting2">
<Columns>
<CC:SortableBoundField HeaderText="First Name" DataField="FirstName" SortExpression="FirstName"
DefaultImageUrl="~/Images/sortable.png" AscImageUrl="~/Images/arrow-up.png" DescImageUrl="~/Images/arrow-dn.png"
meta:resourcekey="BoundFieldFirstNameResource1" ItemStyle-Width="15%" />
<CC:SortableBoundField DataField="MiddleName" HeaderText="Middle Name" SortExpression="MiddleName"
DefaultImageUrl="~/Images/sortable.png" AscImageUrl="~/Images/arrow-up.png" DescImageUrl="~/Images/arrow-dn.png"
meta:resourcekey="BoundFieldMiddleNameResource1" ItemStyle-Width="15%" />
<CC:SortableBoundField DataField="LastName" HeaderText="Last Name" SortExpression="LastName"
DefaultImageUrl="~/Images/sortable.png" AscImageUrl="~/Images/arrow-up.png" DescImageUrl="~/Images/arrow-dn.png"
meta:resourcekey="BoundFieldLastNameResource1" ItemStyle-Width="15%" />
<CC:SortableBoundField DataField="Company" HeaderText="Company" SortExpression="LastName"
DefaultImageUrl="~/Images/sortable.png" AscImageUrl="~/Images/arrow-up.png" DescImageUrl="~/Images/arrow-dn.png"
meta:resourcekey="BoundFieldCompanyResource1" ItemStyle-Width="15%" />
<CC:SortableBoundField DataField="Email" HeaderText="Email" SortExpression="Email"
meta:resourcekey="BoundFieldEmailResource1" DefaultImageUrl="~/Images/sortable.png"
AscImageUrl="~/Images/arrow-up.png" DescImageUrl="~/Images/arrow-dn.png" ItemStyle-Width="16%" />
<CC:SortableBoundField DataField="Phone" HeaderText="Work Phone" SortExpression="Phone"
DefaultImageUrl="~/Images/sortable.png" AscImageUrl="~/Images/arrow-up.png" DescImageUrl="~/Images/arrow-dn.png"
meta:resourcekey="BoundFieldPhoneResource1" ItemStyle-Width="14%" />
<asp:TemplateField>
<ItemTemplate>
<asp:ImageButton ID="ViewButton" runat="server" Width="25px" Height="30px" ToolTip="View"
CommandName="Select" CommandArgument='<%# Eval("ContactID") %>' ImageUrl="~/Images/View_24.png"
meta:resourcekey="GVBtnViewResource1" />
</ItemTemplate>
<ItemStyle HorizontalAlign="Center" Width="5%" />
</asp:TemplateField>
<asp:TemplateField>
<ItemTemplate>
<asp:ImageButton ID="EditButton" runat="server" Width="25px" Height="30px" ToolTip="Edit"
CommandName="Edit" ImageUrl="~/Images/Edit_32x32.png" meta:resourcekey="GVBtnEditResource1" />
</ItemTemplate>
<ItemStyle HorizontalAlign="Center" Width="5%" />
</asp:TemplateField>
</Columns>
</CC:SortableGridView>
System.Web.HttpException was unhandled by user code
Message=The GridView 'ContactsSGV' fired event Sorting which wasn't handled.
Source=System.Web
ErrorCode=-2147467259
WebEventCode=0
StackTrace:
at System.Web.UI.WebControls.GridView.OnSorting(GridViewSortEventArgs e)
at CustomControls.SortableGridView.OnSorting(GridViewSortEventArgs e) in E:\Local\ProTrackPlus_GroupBy2+\CustomControls\SortableGridView.cs:line 314
at System.Web.UI.WebControls.GridView.HandleSort(String sortExpression, SortDirection sortDirection)
at System.Web.UI.WebControls.GridView.HandleSort(String sortExpression)
at System.Web.UI.WebControls.GridView.HandleEvent(EventArgs e, Boolean causesValidation, String validationGroup)
at System.Web.UI.WebControls.GridView.OnBubbleEvent(Object source, EventArgs e)
at System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args)
at System.Web.UI.WebControls.GridViewRow.OnBubbleEvent(Object source, EventArgs e)
at System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args)
at System.Web.UI.WebControls.LinkButton.OnCommand(CommandEventArgs e)
at System.Web.UI.WebControls.LinkButton.RaisePostBackEvent(String eventArgument)
at System.Web.UI.WebControls.LinkButton.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument)
at System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument)
at System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData)
at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
InnerException:
protected void ContactsSGV_RowDataBound(object sender, GridViewRowEventArgs e)
{
//THIS ONE WORKS
var isItWorking = "YES IT IS OMG ";
}
protected void ContactsSGV_Sorting2(object sender, GridViewSortEventArgs e)
{
//THIS IS HELL!
var PLEASE_WORK = true;
}
public class SortableGridView : GridView{
//STUFF
}
protected override void OnSorting(GridViewSortEventArgs e)
{
//This is inside my SortableGridView Class.
//As you can see I am calling the base method and this in fact DOES WORK
//Is my Handler on a page using this control that does not handle the raised event.
setSortData(e.SortExpression);
base.OnSorting(e);
}
为了避免进一步关注第三方控件,我将gridview更改为常规的asp。 这就是结构现在的样子。 ...... 注意:添加链接的声誉不足:(
答案 0 :(得分:0)
您在页面中使用的SortableGridView是第三方控件,它不属于asp控件集。它与asp gridview控件不同。有可能或可能没有onrowdatabound事件的机会。它将取决于控件创建者。右键单击“SortableGridView”类,然后单击“转到定义”,即可查看SortableGridView类中使用的类和方法列表。
答案 1 :(得分:0)
解决了它!!!!! 事实证明,这是一条单线,整个事情都崩溃了。在数据绑定包装函数中有一个ContactsSGV.Dispose()调用,它实际上解除了处理程序的绑定。之前我没有注意它,因为我不确切知道它做了什么。我之前在我正在进行的项目的其他页面上看过它并没有造成任何麻烦。无论如何删除这一行使得一切都适用于常规gridview和我自己的组件。
http://forums.asp.net/t/1336965.aspx/1
关心
0X