1

我一直在努力寻找一个非常令人沮丧的问题。起初是没有触发的 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。这就是现在的结构。......注意:没有足够的声誉添加链接:(

4

2 回答 2

0

您在页面中使用的 SortableGridView 是第三方控件,它不属于 asp 控件集。它与 asp gridview 控件不同。可能会或可能不会发生 onrowdatabound 事件。这取决于控件创建者。您可以通过右键单击“SortableGridView”类并单击“转到定义”,查看 SortableGridView 类中使用的类和方法列表。

于 2012-12-04T12:28:25.330 回答
0

解决了!!!!所以事实证明,这是一条让整个事情崩溃的单行代码。在数据绑定包装函数中有一个 ContactsSGV.Dispose() 调用,它有效地解除了处理程序的绑定。我以前没有注意它,因为我不知道它到底做了什么。我之前在我正在从事的项目的其他页面上看到过它,它没有造成任何麻烦。无论如何,删除这条线使得一切都可以使用常规的 gridview 和我自己的组件。

http://forums.asp.net/t/1336965.aspx/1

问候
0x

于 2012-12-04T15:49:37.420 回答