我们面临的问题是,动态添加到网格过滤器的下拉事件不会触发。由于PageSpreitter中的控件在Page_PreInit事件中不可用,因此在Page_PreInit事件之后添加的处理程序不会被触发。
1)HTML标记如下所示。 请注意,网格不在WebSplitter
中 <asp:ScriptManager ID="SM" runat="server" ScriptMode="Release"></asp:ScriptManager>
<ig:WebSplitter ID="WSP" runat="server">
<Panes>
<ig:SplitterPane runat="server">
<Template>
</Template>
</ig:SplitterPane>
<ig:SplitterPane runat="server"></ig:SplitterPane>
</Panes>
</ig:WebSplitter>
<ig:WebHierarchicalDataGrid ID="WHG" runat="server" Height="350px" Width="400px">
<EditorProviders>
</EditorProviders>
<Behaviors>
<ig:Filtering Enabled="true" CaseSensitive="false" EnableInheritance="true">
</ig:Filtering>
</Behaviors>
</ig:WebHierarchicalDataGrid>
2)代码如下。 请注意,在Page_PreInit事件中调用添加EditiorDropDown的AddEditor()方法。
Protected Sub Page_Init(sender As Object, e As EventArgs) Handles Me.Init
'AddEditor()
End Sub
Protected Sub Page_PreInit(sender As Object, e As EventArgs) Handles Me.PreInit
AddEditor()
End Sub
Protected Sub AddEditor()
Dim sDropdownID As String = ""
sDropdownID = "WHG_DropDownProvider"
WHG.GridView.EditorProviders.Add(GetDropdownProvider(sDropdownID, "ID", "NAME"))
End Sub
Private Function GetDropdownProvider(ByVal i_sDropdownID As String, ByVal i_sValueField As String, ByVal i_sTextField As String) As DropDownProvider
Dim oDropDownProv As New DropDownProvider
oDropDownProv.ID = i_sDropdownID
With oDropDownProv.EditorControl
.EnableMultipleSelection = True
.MultipleSelectionType = DropDownMultipleSelectionType.Checkbox
.EnableAutoFiltering = AutoFiltering.Off
.EnableAutoCompleteFirstMatch = False
.EnableAutoCompleteFirstMatch = False
.EnableClosingDropDownOnSelect = False
.DataKeyFields = i_sValueField
.ValueField = i_sValueField
.TextField = i_sTextField
.DropDownContainerMaxHeight = New Unit("100px")
.DropDownContainerHeight = New Unit("100px")
.BackColor = Drawing.Color.White
.Width = New Unit("99%")
AddHandler .ItemsRequested, AddressOf WHD_DropDownProvider_OnItemsRequested
.EnableAnimations = True
With .ClientEvents
.DropDownOpening = "WHG_DropDownProvider_DropDownOpening"
.DropDownClosing = "WHG_DropDownProvider_DropDownClosing"
End With
End With
Return oDropDownProv
End Function
3)运行网站,尝试对Field1列应用过滤器,然后执行在运行时添加的事件(WHD_DropDownProvider_OnItemsRequested)。 (单击Filter图标并选择Equals,然后单击下拉图标)
这也是我们希望过滤器在下面的场景中工作的方式。
4)现在在WebSplitter中以HTML格式移动网格。所以HTML标记如下所示。
<asp:ScriptManager ID="SM" runat="server" ScriptMode="Release"></asp:ScriptManager>
<ig:WebSplitter ID="WSP" runat="server">
<Panes>
<ig:SplitterPane runat="server">
<Template>
<ig:WebHierarchicalDataGrid ID="WHG" runat="server" Height="350px" Width="400px">
<EditorProviders>
</EditorProviders>
<Behaviors>
<ig:Filtering Enabled="true" CaseSensitive="false" EnableInheritance="true">
</ig:Filtering>
</Behaviors>
</ig:WebHierarchicalDataGrid>
</Template>
</ig:SplitterPane>
<ig:SplitterPane runat="server"></ig:SplitterPane>
</Panes>
</ig:WebSplitter>
5)尝试运行该网站。您将收到对象引用错误。这是因为Page_PreInit事件中的网格不可用。 在这种情况下,网格在Page_Init事件中可用。因此,请在Page_Init事件中调用AddEditor()方法。
Protected Sub Page_Init(sender As Object, e As EventArgs) Handles Me.Init
AddEditor()
End Sub
Protected Sub Page_PreInit(sender As Object, e As EventArgs) Handles Me.PreInit
'AddEditor()
End Sub
Protected Sub AddEditor()
Dim sDropdownID As String = ""
sDropdownID = "WHG_DropDownProvider"
WHG.GridView.EditorProviders.Add(GetDropdownProvider(sDropdownID, "ID", "NAME"))
End Sub
6)现在尝试为Field1列应用过滤器。您会注意到下拉事件没有执行,页面只是刷新。
如果WebSplitter中的控件在page_PreInit事件中可用,则问题将得到解决。
我们找到了部分解决方案。如果我们在Page_PreLoad事件中调用AddEditor(),那么它可以工作。但是,如果我们执行分页/排序操作然后尝试应用EditorDropDown过滤器,那么它将失败并引发对象引用错误。