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

Filter Boxes Not Displayed When Grid is Empty

1 Answer 32 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Allen
Top achievements
Rank 1
Allen asked on 16 Jul 2012, 03:45 PM
I have a page with a grid and when the datasource the grid is bound to has no rows, when the grid displays the filter boxes are not displayed.  A checkbox on the page where the grid is displayed can be checked by the user which then creates a new datasource that does have rows based on a different search criteria and the grid redisplays but the filter boxes are not shown and thus the grid rows cannot be filtered.  Is there a way to force the display of the filter boxes after the datasource is refreshed?

1 Answer, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 17 Jul 2012, 06:41 AM
Hi Allen,

I guess you need to show filtering when the RadGrid is bound on a checkbox checkedchanged event.Please take a look into the following code snippet where Filtering works.

ASPX:
<asp:CheckBox ID="CheckBox1" runat="server" Text="Datasource1" AutoPostBack="true" oncheckedchanged="CheckBox1_CheckedChanged" />
<telerik:RadGrid ID="RadGrid1" runat="server" AutoGenerateColumns="false" AllowFilteringByColumn="true" onneeddatasource="RadGrid1_NeedDataSource" >
    <MasterTableView CommandItemDisplay="Top" ShowHeadersWhenNoRecords="true">
            <Columns>
                    <telerik:GridBoundColumn UniqueName="EmployeeID" HeaderText="EmployeeID"                        DataField="EmployeeID"></telerik:GridBoundColumn>
                    <telerik:GridBoundColumn UniqueName="LastName" HeaderText="LastName" DataField="LastName"></telerik:GridBoundColumn>
            </Columns>
    <MasterTableView/>
</telerik:RadGrid>

C#:
protected void RadGrid1_NeedDataSource(object sender, Telerik.Web.UI.GridNeedDataSourceEventArgs e)
{
    RadGrid1.DataSource = new int[] { };
}
protected void CheckBox1_CheckedChanged(object sender, EventArgs e)
{
    CheckBox CheckBox1 = (CheckBox)sender;
    if (CheckBox1.Checked == true)
    {
 
        string selectQuery1 = "select top 100 EmployeeID,LastName from Employees";
        SqlDataAdapter adapter1 = new SqlDataAdapter(selectQuery1, conn);
        DataTable dt1 = new DataTable();
        conn.Open();
        adapter1.Fill(dt1);
        conn.Close();
        RadGrid1.DataSource = dt1;
        RadGrid1.DataBind();
    }
}

Thanks,
Shinu.
Tags
Grid
Asked by
Allen
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Share this question
or