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

[Solved] show

3 Answers 162 Views
Grid
This is a migrated thread and some comments may be shown as answers.
newbie
Top achievements
Rank 1
newbie asked on 08 Mar 2009, 08:38 PM
I am using custom filtering in  my grid using the filter template as shown here:
http://www.telerik.com/help/aspnet-ajax/radgridfiltertemplate.html

I have a radcombobox in my fliter template.
the issue I have is once i select something in the dropdown and set the filter expression...the gid filters the recordsbut in the display my combobox does not show the selected value.
it defaults to the first item.

How can i retain the combobox selected value?

my grid column declaration:

<

telerik:GridTemplateColumn HeaderText="Name" UniqueName="RelType" HeaderStyle-Width="25%"

 

 

DataField="RelationType">

 

 

<FilterTemplate>

 

 

<telerik:RadComboBox ID="RadComboBoxRelatedContacts" runat="server" AutoPostBack="true" OnSelectedIndexChanged="RadComboBoxRelatedContacts_SelectedIndexChanged">

 

 

<Items>

 

 

<telerik:RadComboBoxItem Text="Family" Value="Family" />

 

 

<telerik:RadComboBoxItem Text="Business" Value="Business" />

 

 

<telerik:RadComboBoxItem Text="Personal" Value="Personal" />

 

</Items>

 

 

</telerik:RadComboBox>

 

 

</FilterTemplate>

 

 

<ItemTemplate><asp:Label ID="Label1" runat="server" CssClass="label" Visible='<%# !Convert.IsDBNull(Eval("Relationship")) %>'><br /><b>Relationship</b>:&nbsp;</asp:Label><%# Eval("Relationship")%>

 

 

<asp:Label ID="Label2" runat="server" CssClass="label" Visible='<%# !Convert.IsDBNull(Eval("RelationType")) %>'><br /><b>Rel. Type</b>:&nbsp;</asp:Label><%# Eval("RelationType")%>

 

 

</ItemTemplate>

 

 

</telerik:GridTemplateColumn>

aspx.cs

protected

void RadComboBoxRelatedContacts_SelectedIndexChanged(object sender, RadComboBoxSelectedIndexChangedEventArgs e)

 

{

 

RadComboBox list = (RadComboBox)sender;

 

 

string filterExpression = "([RelationType] = '" + list.SelectedValue + "')";

 

 

GridFilteringItem item = (GridFilteringItem)list.NamingContainer;

 

 

RadGrid gridKeyRel = (RadGrid)item.NamingContainer.NamingContainer.NamingContainer;

 

gridKeyRel.MasterTableView.FilterExpression = filterExpression;

gridKeyRel.MasterTableView.Rebind(); 

}

3 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 09 Mar 2009, 11:19 AM
Hello,

You can save the selected value of the combobox in the SelectedindexChanged event of the combobox to a global variable and in the PreRender event of the nested grid set that item in the combobox as selected.Check out the code below to understand better:
cs:
string strtxt; 
protected void RadComboBoxRelatedContacts_SelectedIndexChanged(object sender, RadComboBoxSelectedIndexChangedEventArgs e) 
  RadComboBox list = (RadComboBox)sender; 
  strtxt = list.SelectedItem.Text;  
  string filterExpression = "([RelationType] = '" + list.SelectedValue + "')"
  GridFilteringItem item = (GridFilteringItem)list.NamingContainer; 
  RadGrid gridKeyRel = (RadGrid)item.OwnerTableView.NamingContainer; 
  gridKeyRel.MasterTableView.FilterExpression = filterExpression; 
  gridKeyRel.MasterTableView.Rebind();  
 
 
protected void GridKeyRel_PreRender(object sender, EventArgs e) 
 { 
       if (strtxt != null
        { 
            RadGrid grid = (RadGrid)sender; 
            GridFilteringItem filter = (GridFilteringItem)grid.MasterTableView.GetItems(GridItemType.FilteringItem)[0]; 
            RadComboBox combo = (RadComboBox)filter["RelType"].FindControl("RadComboBoxRelatedContacts"); 
            combo.FindItemByText(strtxt).Selected = true
        } 
 } 
 

Thanks
Princy.
0
newbie
Top achievements
Rank 1
answered on 09 Mar 2009, 06:18 PM
thanks!
that worked like a charm.
0
Brian Schmidt
Top achievements
Rank 1
answered on 21 Jan 2010, 09:42 PM
My vb example...

Private strtxt As String  
 
    Protected Sub RadComboBox1_SelectedIndexChanged(ByVal sender As Object, ByVal e As RadComboBoxSelectedIndexChangedEventArgs)  
        Dim list As RadComboBox = DirectCast(sender, RadComboBox)  
        strtxt = list.SelectedItem.Text  
        Dim filterExpression As String  
        filterExpression = "([assigned] = " + e.Value + ")"  
 
        Dim item As GridFilteringItem = DirectCast(list.NamingContainer, GridFilteringItem)  
        Dim gridKeyRel As RadGrid = DirectCast(item.OwnerTableView.NamingContainer, RadGrid)  
 
        RadGrid1.MasterTableView.FilterExpression = filterExpression 
        RadGrid1.MasterTableView.Rebind()  
 
    End Sub  
 
    Protected Sub RadGrid1_PreRender(ByVal sender As Object, ByVal e As EventArgs) Handles RadGrid1.PreRender  
        If strtxt IsNot Nothing Then  
            Dim grid As RadGrid = DirectCast(sender, RadGrid)  
            Dim filter As GridFilteringItem = DirectCast(grid.MasterTableView.GetItems(GridItemType.FilteringItem)(0), GridFilteringItem)  
            Dim combo As RadComboBox = DirectCast(filter("assigned").FindControl("RadComboBox1"), RadComboBox)  
            combo.FindItemByText(strtxt).Selected = True 
        End If  
    End Sub  
 


 

Tags
Grid
Asked by
newbie
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
newbie
Top achievements
Rank 1
Brian Schmidt
Top achievements
Rank 1
Share this question
or