RadGrid Button Column Disable Buttons not in selected row.

3 posts, 0 answers
  1. Eli
    Eli avatar
    10 posts
    Member since:
    Feb 2019

    Posted 14 Feb 2019 Link to this post

    i have a radgrid that i have a buttoncolumn applied. the buttons work fine but i was curious if it is possible to only enable the button for the selected row?

    If no rows are selected all buttons are shown, but disabled. when i click on a row the button on that row becomes enabled, and if i select another row, the button on the row i was on becomes disabled and the new row button is enabled?

    i hope i am clear on this, im still very new to the telerik controls and c#. i have not been able to find anything on this matter.



  2. Attila Antal
    Attila Antal avatar
    608 posts

    Posted 19 Feb 2019 Link to this post

    Hi Elisha,

    One way of achieving that would be on server-side. Here is a short demo video: RadGrid enable button for selected row

    To do that, set the ClientSettings-Selecting-AllowRowSelect and ClientSettings-EnablePostBackOnRowClick properties to True. (marked with yellow). These properties will enable selecting rows as well as do a post back if they are clicked.

    Assuming that there is a GridButtonColumn as well as a GridTemplateColumn, both with buttons (marked with blue). Wire up the PreRender event for the RadGrid. (marked with green)

    RadGrid Markup:

    <telerik:RadGrid ID="RadGrid1" runat="server" AllowPaging="True" Width="800px" OnNeedDataSource="RadGrid1_NeedDataSource" Skin="Bootstrap"
        <ClientSettings EnablePostBackOnRowClick="true">
            <Selecting AllowRowSelect="true" />
        <MasterTableView AutoGenerateColumns="False" DataKeyNames="OrderID">
                <telerik:GridButtonColumn Text="Button" UniqueName="ButtonColumn" ButtonType="PushButton">
                <telerik:GridTemplateColumn UniqueName="TemplateColumn" HeaderText="Template Column">
                        <telerik:RadButton ID="RadButton1" runat="server" Text="RadButton" Enabled="false"></telerik:RadButton>

    C# - Code behind.

    In the PreRender event handler loop through all the grid items, access the Buttons of each control by following the instructions from Accessing Cells and Rows article, and set their Enabled property according to the item's selected state.

    protected void RadGrid1_PreRender(object sender, EventArgs e)
        foreach (GridDataItem item in RadGrid1.Items)
            var btn = item["ButtonColumn"].Controls[0] as Button;
            if (btn != null)
                btn.Enabled = item.Selected;
            var rBtn = item["TemplateColumn"].FindControl("RadButton1") as RadButton;
            if (rBtn != null)
                rBtn.Enabled = item.Selected;

    If in case, you would like to do this on client-side, please let us know. That can be done too, in a slightly different way.

    Kind regards,
    Attila Antal
    Progress Telerik
    Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
  3. Eli
    Eli avatar
    10 posts
    Member since:
    Feb 2019

    Posted 21 Feb 2019 in reply to Attila Antal Link to this post

    This is Perfect!! it is exactly what i needed and has taught me something new. and I have already started modifying it to better suit my project.

    I greatly appreciate the help on this!

Back to Top