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

Radgrid as search

3 Answers 63 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Greg
Top achievements
Rank 1
Greg asked on 27 Jun 2011, 11:07 PM
I'm trying to use the Radgrid as a search form. 

When the grid is first loaded, I want it to bring back zero records, but show the columns and their various filter boxes and the command item section.  When a filter is selected, it then brings back the relevant records.

Currently, I am bringing back the full set of records, and then the user filters from there.  I only want to bring back the records after a filter has been entered.

Thanks!

3 Answers, 1 is accepted

Sort by
0
Genti
Telerik team
answered on 28 Jun 2011, 02:41 PM
Hello Greg,

In this case you can make use of some css.
For example you can define the following:
<style type="text/css">
    .hide{ display:none;}
</style>

And in the page load attach this class to both items and alternating items of the grid.
I.e
private void Page_Load(object sender, System.EventArgs e)
{
    RadGrid1.MasterTableView.ItemStyle.CssClass = "hide";
    RadGrid1.MasterTableView.AlternatingItemStyle.CssClass = "hide";
}

Then in the itemcommand, you can capture the argument of the command and if it is set to filter you can reattach the classes that the items would normally have.
protected void RadGrid1_ItemCommand(object source, GridCommandEventArgs e)
{
    if ((e.CommandName == "Filter"))
    {
        RadGrid1.MasterTableView.ItemStyle.CssClass = "rgRow";
        RadGrid1.MasterTableView.AlternatingItemStyle.CssClass = "rgAltRow";
    }
}

Hope this helps.

Best wishes,
Genti
the Telerik team

Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.

0
Greg
Top achievements
Rank 1
answered on 28 Jun 2011, 08:47 PM
I don't want to hide the records.

I want to not get anything from the database at all until a filter has been entered.

0
Genti
Telerik team
answered on 29 Jun 2011, 09:56 AM
Hi Greg,

Thank you for contacting us again.

In such case you can feed the grid an empty data source in the beginning.
For example in the page load you would have:
private void Page_Load(object sender, System.EventArgs e)
{
    if (!IsPostBack)
    {
        Session["isFirst"] = true;
    }
}

Then, in the NeedDataSource you can do the following:
protected void RadGrid1_NeedDataSource(object source, GridNeedDataSourceEventArgs e)
{
    if (Session["isFirst"] != null && (bool)Session["isFirst"] == true)
    {
        dt = GetDataTable("SELECT Country FROM Customers WHERE 1=2");
        Session["isFirst"] = false;
    }
    else
    {
        dt = GetDataTable("SELECT Country FROM Customers");
    }
    this.RadGrid1.DataSource = dt;
}

If this code brings some exception, try disabling the LinqExpressions in the grid declaration:
EnableLinqExpressions="false"


Hope this helps.

Greetings,
Genti
the Telerik team

Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.

Tags
Grid
Asked by
Greg
Top achievements
Rank 1
Answers by
Genti
Telerik team
Greg
Top achievements
Rank 1
Share this question
or