I have attached 2 files. An aspx page and a code behind vb page. I am trying to apply filter by implementing filter template. I have a radcombobox that filters the radgrid.
Datasource for the radgrid is a dataset defined in aspx.vb. There are 2 tables in the dataset
Radcombobox datasource is a datatable from the above dataset defined in aspx.vb.
Trying to rebind the radgrid after the radcombobox selection both in code behind and on aspx via JS.
1) using the following lines in cmbStateSelectedIndexChanged event does not rebind the grid.
gv_MainStatusDynamic.MasterTableView.FilterExpression = e.Value<
br
> filterItem.FireCommandEvent("Filter", New Pair("Contains", e.Value))<
br
> gv_MainStatusDynamic.Rebind()
2) using FilterExpression in radgrid prerender does not rebind the grid
If isFiltered Then<
br
> If rg_dynamic.MasterTableView.FilterExpression <> "0" Then<
br
> Dim filterItem As GridFilteringItem = TryCast(TryCast(sender, RadComboBox).NamingContainer, GridFilteringItem)<
br
> Dim aCombo As RadComboBox = TryCast(filterItem.FindControl("cmbState"), RadComboBox)<
br
> rg_dynamic.MasterTableView.FilterExpression = Session("StateVal")<
br
> rg_dynamic.MasterTableView.Rebind()<
br
> End If<
br
> End If
3) using filtering in aspx page does not rebind grid.
<
telerik:RadScriptBlock
ID
=
"RadScriptBlock1"
runat
=
"server"
><
br
> <
script
type
=
"text/javascript"
><
br
> function SelectedIndexChanged(sender, args)<
br
> {<
br
> var tableView = $find("<%# TryCast(Container, GridItem).OwnerTableView.ClientID %>");<
br
> tableView.filter("State", args.get_item().get_value(), "EqualTo");<
br
> }<
br
> </
script
><
br
> </
telerik:RadScriptBlock
>
In my first and second cases after I select a state and I do rg_dynamic.MasterTableView.Rebind(), the cmbState will not hold the selected value.
In my third case applying just that code to filter the grid on aspx side (that is commenting filter expression code in grid prerender and combobox selected index changed server side events) will hold the selected value.
I have the datasource available for both grid and combox box on my server side. The grid will not rebind post filtered value. I came across an example on your forum pages http://demos.telerik.com/aspnet-ajax/grid/examples/functionality/filtering/filter-templates/defaultcs.aspx
But it is not helping me.
Any help on this is appreciated.
Here is my aspx.vb
Protected Sub rg_dynamic_NeedDataSource(sender As Object, e As GridNeedDataSourceEventArgs) Handles rg_dynamic.NeedDataSource<
br
> rg_dynamic.DataSource = GetData()<
br
> End Sub<
br
> <
br
> Private Function GetData() As DataSet<
br
> Using oConn As SqlConnection = New SqlConnection(GenConn())<
br
> 'Gets dataset object<
br
> End Using<
br
> End Function<
br
> <
br
> Protected Sub rg_dynamic_ItemCreated(sender As Object, e As GridItemEventArgs) Handles rg_dynamic.ItemCreated<
br
> If TypeOf e.Item Is GridFilteringItem Then<
br
> Dim filterItem As GridFilteringItem = DirectCast(e.Item, GridFilteringItem)<
br
> Dim cmbState As RadComboBox = DirectCast(filterItem("State").FindControl("cmbState"), RadComboBox)<
br
> cmbState.SelectedValue = e.Item.OwnerTableView.GetColumn("State").CurrentFilterValue<
br
> RefreshStateCombo(cmbState) <
br
> End If<
br
> End Sub<
br
> <
br
> Protected Sub RefreshStateCombo(ByVal stCombo As RadComboBox)<
br
> Dim SprocData As DataSet = GetData()<
br
> Dim oDbDS As New DataBaseUtils2<
br
> Dim StateDate As DataView = SprocData.Tables(0).DefaultView<
br
> Dim dtStatedata As DataTable = StateDate.Table()<
br
> stCombo.DataSource = StateDate<
br
> stCombo.DataTextField = dtStatedata.Columns(1).ToString() 'name of the state<
br
> stCombo.DataValueField = dtStatedata.Columns(0).ToString() 'StateCompID<
br
> End Sub<
br
> <
br
> <
br
> Protected Sub rg_dynamic_PreRender(sender As Object, e As EventArgs) Handles rg_dynamic.PreRender<
br
> If isFiltered Then<
br
> If rg_dynamic.MasterTableView.FilterExpression <> "0" Then<
br
> Dim filterItem As GridFilteringItem = TryCast(TryCast(sender, RadComboBox).NamingContainer, GridFilteringItem)<
br
> Dim aCombo As RadComboBox = TryCast(filterItem.FindControl("cmbState"), RadComboBox)<
br
> rg_dynamic.MasterTableView.FilterExpression = Session("StateVal")<
br
> rg_dynamic.MasterTableView.Rebind()<
br
> End If<
br
> End If<
br
> End Sub<
br
> <
br
> Private isFiltered As Boolean = false<
br
> Protected Sub cmbStateSelectedIndexChanged(sender As Object, e As RadComboBoxSelectedIndexChangedEventArgs) <
br
> If e.Value <> "0" Then<
br
> isFiltered = True<
br
> Session("StateVal") = e.Value<
br
> End If<
br
> 'Dim filterItem As GridFilteringItem = TryCast(TryCast(sender, RadComboBox).NamingContainer, GridFilteringItem)<
br
> 'filterItem.OwnerTableView.GetColumn("StateCompID").CurrentFilterValue = e.Value ''CAPTURE THIS VALUE in a property<
br
> 'rg_dynamic.MasterTableView.FilterExpression = e.Value<
br
> 'filterItem.FireCommandEvent("Filter", New Pair("EqualTo", e.Value))<
br
> ' rg_dynamic.Rebind()<
br
> End Sub
Here is my aspx
<
Telerik:Radgrid
ID
=
"rg_dynamic"
runat
=
"server"
DataKeyNames
=
"StateCompID"
EnableLinqExpressions
=
"false"
<br> BorderStyle="Solid" CellSpacing="0" BorderWidth="1px" AllowAutomaticDeletes="false" AllowMultiRowSelection="false"<
br
> AllowAutomaticInserts="false" AllowAutomaticUpdates="false" AutoGenerateColumns="False" AllowFilteringByColumn="true"<
br
> AllowSorting="True" GridLines="None" AllowPaging="false" Width="100%" MasterTableView-EnableColumnsViewState="false"><
br
> <
br
> <
MasterTableView
><
br
> <
Columns
><
br
> <
br
> <
telerik:GridBoundColumn
DataField
=
"StateCompID"
Visible
=
"False"
HeaderText
=
"StateCompID"
<br> ItemStyle-HorizontalAlign="Left" ReadOnly="True" UniqueName="StateCompID" <
br
> SortExpression="StateCompID"> </
telerik:GridBoundColumn
><
br
> <
br
> <
br
> <
telerik:GridBoundColumn
DataField
=
"State"
HeaderText
=
"State"
SortExpression
=
"State"
HeaderStyle-Width
=
"175"
UniqueName
=
"State"
AllowFiltering
=
"true"
AutoPostBackOnFilter
=
"true"
><
br
> <
FilterTemplate
><
br
> <
telerik:RadComboBox
RenderMode
=
"Lightweight"
ID
=
"cmbState"
AutoPostBack
=
"true"
AutoPostBackOnFilter
=
"true"
<br> Width="200px" AppendDataBoundItems="true" SelectedValue='<%# TryCast(Container, GridItem).OwnerTableView.GetColumn("State").CurrentFilterValue%>'<
br
> runat="server" OnClientSelectedIndexChanged="SelectedIndexChanged" OnSelectedIndexChanged="cmbStateSelectedIndexChanged" ><
br
> <
Items
><
br
> <
telerik:RadComboBoxItem
Text
=
"All"
Value
=
"0"
/><
br
> </
Items
><
br
> </
telerik:RadComboBox
><
br
> <
telerik:RadScriptBlock
ID
=
"RadScriptBlock1"
runat
=
"server"
><
br
> <
script
type
=
"text/javascript"
><
br
> function SelectedIndexChanged(sender, args)<
br
> {<
br
> var tableView = $find("<%# TryCast(Container, GridItem).OwnerTableView.ClientID %>");<
br
> tableView.filter("State", args.get_item().get_value(), "EqualTo");<
br
> }<
br
> </
script
><
br
> </
telerik:RadScriptBlock
><
br
> </
FilterTemplate
><
br
> </
telerik:GridBoundColumn
><
br
> <
telerik:GridBoundColumn
DataField
=
"Company"
HeaderText
=
"Company Type"
ReadOnly
=
"True"
SortExpression
=
"Company"
UniqueName
=
"Company"
<br> ItemStyle-HorizontalAlign="Center" AllowFiltering="false" ShowFilterIcon="false"><
br
> <
br
> </
telerik:GridBoundColumn
><
br
> </
Columns
><
br
> </
MasterTableView
><
br
> <
HeaderContextMenu
CssClass
=
"GridContextMenu GridContextMenu_Default"
><
br
> </
HeaderContextMenu
><
br
>
</
Telerik:Radgrid
>