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

Set Default Combo Index Selected Filter Template

2 Answers 184 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Ryan
Top achievements
Rank 1
Ryan asked on 01 Sep 2011, 09:44 PM
I have a radgrid with a column that has a RADCOMBO set in the filter Template. How do I set the the default filter index of the RADCOMBO on first time page load to another index programatically (in my case "Show Only Null" as opposed to "ALL").  I tried this code in both preRender and itemDataBound but it only sets the text and does not actually filter the data. The second part of the code shows the set up of the column in the aspx file. Can you provide me exact code? Thanks!

//tried this in preRender and itemDataBound methods
GridFilteringItem filterItem = (GridFilteringItem)e.Item;
RadComboBox combo = (RadComboBox)filterItem.FindControl("PROB_DATE");
combo.SelectedIndex = 1;




 <telerik:GridBoundColumn ForceExtractValue="Always" DataField="PROB_DATE" ReadOnly="True" DataType="System.DateTime"
                    FilterControlAltText="Filter PROB_DATE column" HeaderText="PROB DATE RESOLVED"
                    SortExpression="PROB_DATE" UniqueName="PROB_DATE" DataFormatString="{0:MM/dd/yyyy}">


                    <FilterTemplate>
                        <telerik:RadComboBox ID="RadComboBoxPROB_DATE" DataSourceID="SqlDataSourceMyDataSource"
                            DataTextField="PROB_DATE" DataValueField="PROB_DATE" Height="200px" AppendDataBoundItems="true"
                            SelectedValue='<%# ((GridItem)Container).OwnerTableView.GetColumn("PROB_DATE").CurrentFilterValue %>'
                            runat="server" OnClientSelectedIndexChanged="PROB_DATEIndexChanged" Width="140px">
                            <Items>
                                <telerik:RadComboBoxItem Text="ALL" />
                            </Items>
                        </telerik:RadComboBox>
                        <telerik:RadScriptBlock ID="RadScriptBlockPROB_DATE" runat="server">
                            <script type="text/javascript">
                                function PROB_DATEIndexChanged(sender, args) {
                                    var value2 = args.get_item().get_value();


                                    if (value2 == 'Show Only Null') {
                                        var tableView = $find("<%# ((GridItem)Container).OwnerTableView.ClientID %>");
                                        tableView.filter("PROB_DATE", args.get_item().get_text(), "IsNull");
                                    }
                                    else {
                                        var tableView = $find("<%# ((GridItem)Container).OwnerTableView.ClientID %>");
                                         tableView.filter("PROB_DATE", args.get_item().get_value(), "NoFilter");
                                    }


                                //}
                            </script>
                        </telerik:RadScriptBlock>
                    </FilterTemplate>


                </telerik:GridBoundColumn>







2 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 02 Sep 2011, 07:13 AM
Hello Ryan,

Take a look at the following demo which implements the same.
Grid / Filter Templates.

Thanks,
Princy.
0
Ryan
Top achievements
Rank 1
answered on 02 Sep 2011, 02:21 PM
Okay thanks that pointed me in the right direction. For anyone that finds this still unclear here is my solution: First set the selected index of the combobox in the RadGrid1_ItemDataBound method. Then filter the data in the RadGrid1_PreRender. See my code below

protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)
{
 
if (e.Item is GridFilteringItem)
            {
                GridFilteringItem filterItem = (GridFilteringItem)e.Item;
                RadComboBox combo = (RadComboBox)filterItem.FindControl("RadComboBoxPROB_DATE");
 
                if (!IsPostBack)
                {
                    //set which index you would like initially selected here
                    combo.SelectedIndex = 1;
                }
            }
}
 
 
protected void RadGrid1_PreRender(object sender, System.EventArgs e)
{
 
            if (!IsPostBack)
            {
               //set initial filter on data here (which should correspond to the selected index above)
                SqlDataSourceMyDataSource.SelectCommand = "SELECT * FROM PROB_DATA_BASE WHERE PROB_DATE IS               NULL";
            }
 
}

Tags
Grid
Asked by
Ryan
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Ryan
Top achievements
Rank 1
Share this question
or