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

RadGrid Filter Template by Combo Box. Show All, Null Value as Well Selected Value.

4 Answers 307 Views
Grid
This is a migrated thread and some comments may be shown as answers.
gc_0620
Top achievements
Rank 1
gc_0620 asked on 08 Apr 2014, 02:15 AM
Folks using UI for ASP.NET AJAX Q1 2014 with VS 2012.

I am using below link as Prototype (The Top Grid).

http://demos.telerik.com/aspnet-ajax/grid/examples/functionality/filtering/filter-templates/defaultcs.aspx

I would like to Filter the RadGrid Based on Null Value of the City Combobox as Well as All or Selected Value. I modified the Screen (See attached).

Below is my new Datasource for that ComboBox (i.e RadComboBoxCity) that already has some Null City Values.

<asp:SqlDataSource ID="SqlDataSource3"
        ConnectionString="<%$ ConnectionStrings:NorthwindConnectionString %>" SelectCommand="SELECT DISTINCT City  FROM CustCity"
        runat="server"></asp:SqlDataSource>

Also there are Some Null City Values in Customer Table.

<asp:SqlDataSource ID="SqlDataSource1" ConnectionString="<%$ ConnectionStrings:NorthwindConnectionString %>"
        ProviderName="System.Data.SqlClient" SelectCommand="SELECT CustomerID, ContactName, ContactTitle, City, Country, Bool FROM Customers"
        runat="server"></asp:SqlDataSource>

Any Help is appreciated. Thanks

gc_0620

4 Answers, 1 is accepted

Sort by
0
gc_0620
Top achievements
Rank 1
answered on 08 Apr 2014, 02:19 AM
Sorry Attachment was not uploaded. Here we go. Thanks again
0
Princy
Top achievements
Rank 2
answered on 08 Apr 2014, 04:34 AM
Hi,

Please try the following code snippet.

ASPX:
<telerik:GridBoundColumn DataField="ShipCity" HeaderText="ShipCity" SortExpression="ShipCity"UniqueName="ShipCity">
    <FilterTemplate>
        <telerik:RadComboBox ID="RadComboBoxCity" DataSourceID="SqlDataSource1" DataTextField="ShipCity" DropDownWidth="200px" DataValueField="ShipCity" Height="100px" AppendDataBoundItems="true"  SelectedValue='<%# Container.OwnerTableView.GetColumn("ShipCity").CurrentFilterValue %>' runat="server" OnClientSelectedIndexChanged="ShipCityIndexChanged" Filter="StartsWith">
            <Items>
                <telerik:RadComboBoxItem Text="All" />
                <telerik:RadComboBoxItem Text="IsEmpty" Value=" " />
                <telerik:RadComboBoxItem Text="IsNull" Value="Null" />
            </Items>
        </telerik:RadComboBox>
        <telerik:RadScriptBlock ID="RadScriptBlock" runat="server">
            <script type="text/javascript">
                function ShipCityIndexChanged(sender, args) {
                    var tableView = $find("<%# Container.OwnerTableView.ClientID %>");
                    var value = args.get_item().get_value();
                    if (value == "Null") {
                        tableView.filter("ShipCity", args.get_item().get_value(), "IsNull");
                    }
                    else {
                        tableView.filter("ShipCity", args.get_item().get_value(), "EqualTo");
                    }
                }
            </script>
        </telerik:RadScriptBlock>
    </FilterTemplate>
</telerik:GridBoundColumn>

Thanks,
Princy
0
gc_0620
Top achievements
Rank 1
answered on 08 Apr 2014, 05:42 PM
Thanks so much Princy for your help, as always your solution works. One more small favor.

Let's see I have below Table in Child Grid Form Template. What will be the correct syntax to refer the below Table elements (in this example: DropDownList ddlTOC and TextBox TextBoxFirstName) from Client Side? .

Regards

gc_0620


<table>
  <tr>
     <td>
     <asp:DropDownList ID="ddlTOC" runat="server" SelectedValue='<%# Bind("TitleOfCourtesy") %>'
                  DataSource='<%# (new string[] { "Dr.", "Mr.", "Mrs.", "Ms." }) %>' TabIndex="7"
                   AppendDataBoundItems="True">
                <asp:ListItem Selected="True" Text="Select" Value="">
                   </asp:ListItem>
      </asp:DropDownList>
     </td>
     <td>
           FirstName:
      </td>
      <td>
        <asp:TextBox ID="TextBoxFirstName" Text='<%# Bind( "FirstName") %>' runat="server"
                 TabIndex="8">
        </asp:TextBox>
       </td>
                        </tr>
                    </table>
0
Princy
Top achievements
Rank 2
answered on 09 Apr 2014, 07:01 AM
Hi,

I'm not sure where you want to access the controls, please take a look at the sample code, i have access the controls on a button click which is inside the form template.

C#:
protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)
{
    if (e.Item is GridEditableItem && e.Item.IsInEditMode && e.Item.OwnerTableView.Name == "ChildTableName")
    {
        GridEditFormItem edit = (GridEditFormItem)e.Item;
        DropDownList droplist = (DropDownList)edit.FindControl("ddlTOC");
        TextBox txt = (TextBox)edit.FindControl("TextBoxFirstName");
        Button btn = (Button)edit.FindControl("Button1");
        btn.Attributes.Add("OnClick", "return EditForm('" + droplist.ClientID + "','" + txt.ClientID + "');");
    }
}

JS:
<script type="text/javascript">
    function EditForm(ddl, txt) {     
        var dropdownlist = document.getElementById(ddl); // Access dropdownlist
        var textbox = document.getElementById(txt); //Access textbox
    }
</script>

Thanks,
Princy
Tags
Grid
Asked by
gc_0620
Top achievements
Rank 1
Answers by
gc_0620
Top achievements
Rank 1
Princy
Top achievements
Rank 2
Share this question
or