Display only InsertForm, hide other gridview elements

3 posts, 0 answers
  1. kzimny
    kzimny avatar
    7 posts
    Member since:
    Jul 2007

    Posted 17 Sep 2014 Link to this post

    Does anybody know how to hide all grid items in MastertableView and DetailTableVies after clicking on "Add new item" button?
    I wont to Display only the insert form and hide all ofter GridView elements:


    protected void GrdTicketsItemCommand(object sender, GridCommandEventArgs e)
    {
        if (e.CommandName == RadGrid.InitInsertCommandName)
        {
            // show insert form works fine
            e.Item.OwnerTableView.EditFormSettings.UserControlName = "BackendControls/AddBillingAndTicket.ascx";
            e.Item.OwnerTableView.EditFormSettings.EditFormType = GridEditFormType.WebUserControl;
            e.Item.OwnerTableView.InsertItem();
     
            // How to hide all items in MasterTableView and all DetailsTables?
            // this doesn't work:
            foreach (GridDataItem item in GrdTickets.Items)
                item.Visible = false;
        }
    }


    Thank you for your help.
    Christopher
  2. Konstantin Dikov
    Admin
    Konstantin Dikov avatar
    1793 posts

    Posted 22 Sep 2014 Link to this post

    Hello Christopher,

    For achieving the desired result you can handle the server-side OnPreRender event of the grid and if the MasterTableView's IsItemInserted property is true, traverse through each item and set its Visible property to false:
    protected void RadGrid1_PreRender(object sender, EventArgs e)
    {
        if (RadGrid1.MasterTableView.IsItemInserted)
        {
            foreach (GridDataItem item in RadGrid1.Items)
            {
                item.Visible = false;
            }
        }
    }

    The same approach could be used for the detail tables as well.

    Please give this a try and see if the result meets your requirements.
     

    Regards,
    Konstantin Dikov
    Telerik
     

    Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

     
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. kzimny
    kzimny avatar
    7 posts
    Member since:
    Jul 2007

    Posted 22 Sep 2014 in reply to Konstantin Dikov Link to this post

    Thank you Konstantin! I've modified you code a little for hierarchical grids:

    protected void GrdTickets_PreRender(object sender, EventArgs e)
    {
        if (GrdTickets.MasterTableView.IsItemInserted)
        {
            foreach (GridDataItem item in GrdTickets.MasterTableView.Items)
            {
                if (item.HasChildItems)
                {
                    GridTableView tableView = item.ChildItem.NestedTableViews[0];
                    tableView.Visible = false;
                    tableView.DataBind();
     
                    item.Visible = false;
                }
            }
        }
    }


    Kind regards,
    Christopher
Back to Top