This is a migrated thread and some comments may be shown as answers.

[Solved] DataBinding not called after Filtering

6 Answers 345 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Jocelyn
Top achievements
Rank 1
Jocelyn asked on 09 May 2013, 12:36 PM
Hi,

I have a problem where the DataBinding event of my RadGrid is not called after a Filter on any column. The event is only called on the very first binding of the grid or if I call a Rebind(). 

I can see that on filter, it correctly call ItemCommand -> NeedDataSource -> DataBound, but not DataBinding before DataBound.

Is that a normal behavior or this is an issue? 

Thanks.

6 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 09 May 2013, 12:52 PM
Hi,

I am not sure about the requirement. If you are using Advanced DataBinding method, NeedDataSource event will be fired after the filter operation(for the Inbuilt filtering). If you are customizing filtering, then you need to call Rebind() method to call the NeedDataSouce event after filter.

Thanks,
Princy.
0
Jocelyn
Top achievements
Rank 1
answered on 09 May 2013, 01:27 PM
Hi Princy,

It actually call OnNeedDataSource after the filter, but it does not call OnDataBinding for some reason and it does call the OnDataBound..

I use the Advanced DataBinding.

Here is my simple grid:

<form id="form1" runat="server">
<telerik:RadScriptManager ID="RadScriptManager1" runat="server">
    <Scripts>
        <asp:ScriptReference Assembly="Telerik.Web.UI" Name="Telerik.Web.UI.Common.Core.js">
        </asp:ScriptReference>
        <asp:ScriptReference Assembly="Telerik.Web.UI" Name="Telerik.Web.UI.Common.jQuery.js">
        </asp:ScriptReference>
        <asp:ScriptReference Assembly="Telerik.Web.UI" Name="Telerik.Web.UI.Common.jQueryInclude.js">
        </asp:ScriptReference>
    </Scripts>
</telerik:RadScriptManager>
<telerik:RadAjaxManager ID="RadAjaxManager1" runat="server" ClientEvents-OnResponseEnd="OnResponseEnd">
    <AjaxSettings>
        <telerik:AjaxSetting AjaxControlID="gridTest">
            <UpdatedControls>
                <telerik:AjaxUpdatedControl ControlID="gridTest" />
            </UpdatedControls>
        </telerik:AjaxSetting>
    </AjaxSettings>
</telerik:RadAjaxManager>
<div>
    <telerik:RadGrid runat="server" ID="gridTest">
        <MasterTableView>
            <Columns>
                <telerik:GridBoundColumn HeaderText="Colonne 1" DataField="Col1" AllowFiltering="true"
                    AutoPostBackOnFilter="true" UniqueName="colUn" CurrentFilterFunction="StartsWith">
                </telerik:GridBoundColumn>
                <telerik:GridBoundColumn HeaderText="Colonne 2" DataField="Col2" AllowFiltering="true"
                    AutoPostBackOnFilter="true" UniqueName="colDeux" CurrentFilterFunction="StartsWith">
                </telerik:GridBoundColumn>
                <telerik:GridBoundColumn HeaderText="Colonne 3" DataField="Col3" AllowFiltering="true"
                    AutoPostBackOnFilter="true" UniqueName="colTrois" CurrentFilterFunction="StartsWith">
                </telerik:GridBoundColumn>
            </Columns>
        </MasterTableView>
    </telerik:RadGrid>
</div>
</form>

Here is my VB:

Partial Public Class testpage
    Inherits Page
 
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        gridTest.AllowFilteringByColumn = True
    End Sub
 
    Private Sub gridTest_DataBinding(ByVal sender As Object, ByVal e As System.EventArgs) Handles gridTest.DataBinding
        Debug.WriteLine("Hi!")
    End Sub
 
    Private Sub gridTest_NeedDataSource(ByVal sender As Object, ByVal e As Telerik.Web.UI.GridNeedDataSourceEventArgs) Handles gridTest.NeedDataSource
        Dim tbl As New DataTable()
 
        tbl.Columns.Add("Col1", GetType(String))
        tbl.Columns.Add("Col2", GetType(String))
        tbl.Columns.Add("Col3", GetType(String))
 
        tbl.Rows.Add("Test", "teeessttt", "aaaééééé")
        tbl.Rows.Add("Tést", "téééssttt", "éééééééé")
        tbl.Rows.Add("Tast", "teéessttt", "reeééééé")
        tbl.Rows.Add("Tàst", "teeessttt", "eeeééééé")
        tbl.Rows.Add("Test", "teèessttt", "àééééé")
 
        gridTest.DataSource = tbl
    End Sub
End Class

On the first load, it calls NeedDataSource and will show "Hi!" in the console. If I filter a column, it will still call NeedDataSource, but will not call DataBinding after that.

Thanks.
0
Princy
Top achievements
Rank 2
answered on 10 May 2013, 04:12 AM
Hi Jocelyn,

I tried your code and its working fine at my end. After filter operation data in RadGrid in bound using NeedDataSource, If you want to do any operation after filter you can do it in ItemCreated/ItemDataBound event. Please take a look into this help documentation which describes about the event sequence in RadGrid.  Elaborate your scenario if it doesn't help.

Thanks,
Princy.
0
Jocelyn
Top achievements
Rank 1
answered on 10 May 2013, 02:40 PM
Hi Princy,

I don't know why DataBinding is never called after filter. I tried to update my Telerik version, but it still don't work.

I need to execute some code before the Data binds directly after the NeedDataSource for grids all over my application.

So I added a Handler in the load event of each page for NeedDataSource. So my custom NeedDataSource is called after the first NeedDataSource.

Sorry if my solution is complex. English is not my main language.

Thanks for your help.
0
Princy
Top achievements
Rank 2
answered on 13 May 2013, 04:53 AM
Hi,

One suggestion is to try code inside ItemCreated event .

Thanks,
Princy.
0
Jocelyn
Top achievements
Rank 1
answered on 13 May 2013, 07:29 PM
Hi,

I found a solution. I added a second handler OnNeedDataSource and it works well.

Thanks for you help!
Tags
Grid
Asked by
Jocelyn
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Jocelyn
Top achievements
Rank 1
Share this question
or