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

Display only InsertForm, hide other gridview elements

2 Answers 20 Views
Grid
This is a migrated thread and some comments may be shown as answers.
kzimny
Top achievements
Rank 1
kzimny asked on 17 Sep 2014, 08:49 PM
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 Answers, 1 is accepted

Sort by
0
Konstantin Dikov
Telerik team
answered on 22 Sep 2014, 11:39 AM
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.

 
0
kzimny
Top achievements
Rank 1
answered on 22 Sep 2014, 06:43 PM
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
Tags
Grid
Asked by
kzimny
Top achievements
Rank 1
Answers by
Konstantin Dikov
Telerik team
kzimny
Top achievements
Rank 1
Share this question
or