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

Need to enable/disable commanditem based on no. of records in the grid

4 Answers 57 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Priyank
Top achievements
Rank 1
Priyank asked on 19 Nov 2013, 10:27 AM
Hello,

I have a linkbutton in the commanditem template.

I need to disable this linkbutton when the grid has 0 records.

Any help will be appreciated.

Thanks,
Priyank

4 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 19 Nov 2013, 11:05 AM
Hi Priyank,

Please try the following code snippet to disable a LinkButton inside CommandItemTemplate.

ASPX:
<CommandItemTemplate>
    <asp:LinkButton ID="LinkButton1" runat="server">LinkButton</asp:LinkButton>
</CommandItemTemplate>

C#:
protected void RadGrid1_PreRender(object sender, EventArgs e)
{
    RadGrid1.AllowPaging = false;
    RadGrid1.Rebind();
    int count = RadGrid1.MasterTableView.Items.Count; //Get the count of rows
    RadGrid1.AllowPaging = true;
    RadGrid1.Rebind();
    foreach (GridCommandItem cmditm in RadGrid1.MasterTableView.GetItems(GridItemType.CommandItem))
    {
        if (count == 0)
        {
            LinkButton lnkbtn = (LinkButton)cmditm.FindControl("LinkButton1");
            lnkbtn.Enabled = false;
        }
    }
}

Thanks,
Princy
0
Priyank
Top achievements
Rank 1
answered on 19 Nov 2013, 12:43 PM
Hi Princy,

As per your suggested solution, the linkbutton is enabled and disabled as per the grid items count but now the collapse/expand button of grid item is not working and the linkbutton's click event is not getting executed.

Thanks,
Priyank
0
Princy
Top achievements
Rank 2
answered on 20 Nov 2013, 08:51 AM
Hi Priyank,

Please try setting the HierarchyLoadMode="Client" property in the MasterTableView of the Radgrid, also set the ClientSettings AllowExpandCollapse="true".

ASPX:
<MasterTableView HierarchyLoadMode="Client". . .>
. . . . . .
<ClientSettings AllowExpandCollapse="true"/>

Thanks,
Princy
0
Priyank
Top achievements
Rank 1
answered on 20 Nov 2013, 12:32 PM
Thanks a lot Princy.
It worked!!

Thanks,
Priyank
Tags
Grid
Asked by
Priyank
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Priyank
Top achievements
Rank 1
Share this question
or