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

Hide Add New Record Button

4 Answers 501 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Ed
Top achievements
Rank 1
Ed asked on 17 Oct 2012, 11:04 AM
I am using version 2012.2.912.40 of the ASP.Net product. I want to conditionally hide the Add New Record button. The condition is based on the row count. I am currently using the grid DataBound event to do this. It works whenever I insert or delete a row, but not on the initial load of the grid. The event is firing and the code to hide the button is executed, but it does not happen. Is there some action that is occurring later in the life cycle during the initial load that would cause the default setting to be used?

4 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 17 Oct 2012, 11:34 AM
Hi,

Try the following code to hide the button conditionally.
C#:
protected void RadGrid1_PreRender(object sender, EventArgs e)
{
    int count = RadGrid1.MasterTableView.Items.Count;
    if (count == 10)
    {
        foreach (GridCommandItem item in RadGrid1.MasterTableView.GetItems(GridItemType.CommandItem))
        {
            Button btn = (Button)item.FindControl("AddNewRecordButton");
            LinkButton Addbtn = (LinkButton)item.FindControl("InitInsertButton");
            btn.Visible = false;
            Addbtn.Visible = false;
        }
    }
}

Thanks,
Shinu.
0
Ed
Top achievements
Rank 1
answered on 17 Oct 2012, 12:08 PM
Shinu,

Thaniks for the reply.
I am not trying to hide buttons on the rows but rather the Add New Record button above the grid.
The code that I am using is:

this

 

 

.CalendarIntervalsGrid.MasterTableView.CommandItemSettings.ShowAddNewRecordButton = this.CalendarIntervalsGrid.MasterTableView.Items.Count < 4;

 


This works fine when I add or delete rows, just not when the page initially loads.
0
Accepted
Shinu
Top achievements
Rank 2
answered on 18 Oct 2012, 05:02 AM
Hi,

Try hiding the button in Prerender event as shown below.
C#:
protected void RadGrid1_PreRender(object sender, EventArgs e)
{
    int count = RadGrid1.MasterTableView.Items.Count;
    if (count == 10)
    {
        RadGrid1.MasterTableView.CommandItemSettings.ShowAddNewRecordButton = false;
        RadGrid1.Rebind();
    }
}

Thanks,
Shinu.
0
Ed
Top achievements
Rank 1
answered on 18 Oct 2012, 10:49 AM
Shinu,

I had tried it on the PreRender, but forgot to include the ReBind().
Thanks.
Tags
Grid
Asked by
Ed
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Ed
Top achievements
Rank 1
Share this question
or