Radgrid as search

4 posts, 0 answers
  1. Greg
    Greg avatar
    17 posts
    Member since:
    Oct 2010

    Posted 27 Jun 2011 Link to this post

    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!
  2. Genti
    Admin
    Genti avatar
    107 posts

    Posted 28 Jun 2011 Link to this post

    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.

  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Greg
    Greg avatar
    17 posts
    Member since:
    Oct 2010

    Posted 28 Jun 2011 Link to this post

    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.

  5. Genti
    Admin
    Genti avatar
    107 posts

    Posted 29 Jun 2011 Link to this post

    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.

Back to Top