Disable selection for some rows in GridClientSelectColumn conditionally

Thread is closed for posting
5 posts, 0 answers
  1. 63F75A2C-1F16-4AED-AFE8-B1BBD57646AD
    63F75A2C-1F16-4AED-AFE8-B1BBD57646AD avatar
    1572 posts
    Member since:
    Oct 2004

    Posted 16 Apr 2007 Link to this post

    Requirements

    RadGrid for ASP .NET version

    RadControls for ASP .NET AJAX version

    Q4 2006 SP2 and later


    2008.1.415 and later
    .NET version

    2.0 and later
    Visual Studio version

    2005 and later
    Programming language

    C#, Javascrpt
    Browser support

    all supported by RadGrid for ASP .NET


    all browsers supported by RadControls for ASP .NET AJAX

    To convert code from posted projects Telerik online converter


    PROJECT DESCRIPTION


    In some particular cases you may need to disallow selection for part of the rows in grid having GridClientSelectColumn. Wiring the ItemCreated or ItemDataBound events and disabling the checkbox in that GridClientSelectColumn solves the problem partially. Still if the checkbox in the grid header is checked -- all grid items become selected.

    The attached project uses a hidden input to send the indexes of the non-selectable items to the client. On the client these values are loaded into an array. Then inside RowSelecting client event handler of the grid a javascript function is executed to check if the index of the row being selected is in the list. If that is true the event has been cancelled.

    Below is the essential part of the code:

    protected void RadGrid1_ItemDataBound(object sender, Telerik.WebControls.GridItemEventArgs e) 
        if (e.Item is GridDataItem) //Your condition goes here 
        { 
            ((e.Item as GridDataItem)["Select"].Controls[1] as CheckBox).Enabled = false
            Sel.Value += e.Item.ItemIndex.ToString() + ":"
        } 

        <script type="text/javascript"
        var a = Array; 
        window.onload = function () 
        { 
            var inp = document.getElementById('Sel'); 
            var data = inp.value; 
            if(data != ""
            { 
                var rowsData = data.split(":"); 
                var i=0; 
                while(typeof(rowsData[i]) != "undefined"
                { 
                    if (rowsData[i] != ""
                    { 
                        a[i] = rowsData[i]; 
                    } 
                    i++; 
                } 
            } 
        }     
        function Selecting (row)  
        { 
            var i = 0; 
            while(typeof(a[i]) != "undefined"
            { 
                if (a[i++] == row.Index) 
                { 
                    return false
                } 
            } 
        } 
        </script> 
     
  2. 63F75A2C-1F16-4AED-AFE8-B1BBD57646AD
    63F75A2C-1F16-4AED-AFE8-B1BBD57646AD avatar
    1572 posts
    Member since:
    Oct 2004

    Posted 09 Jul 2007 Link to this post

    The additional literal control, part of GridClientSelectColumn's cells, has been removed since v4.6.2 of RadGrid. So the code above needs to be modified a bit:

        protected void RadGrid1_ItemDataBound(object sender, Telerik.WebControls.GridItemEventArgs e) 
        { 
            if (e.Item is GridDataItem &&  
               (e.Item.ItemIndex == 5 || e.Item.ItemIndex == 6 || e.Item.ItemIndex == 1))   //Your condition goes here 
            { 
                ((e.Item as GridDataItem)["Select"].Controls[0] as CheckBox).Enabled = false;  // first control since v4.6.2 
                Sel.Value += e.Item.ItemIndex.ToString() + ":"
            } 
        } 

    Attachment added into initial post.
  3. 63F75A2C-1F16-4AED-AFE8-B1BBD57646AD
    63F75A2C-1F16-4AED-AFE8-B1BBD57646AD avatar
    1572 posts
    Member since:
    Oct 2004

    Posted 18 Feb 2008 Link to this post

    Hello,

    Attached to the initial post, you will find the same technique working with Telerik.Web.UI RadGrid. The JavaScript code is pretty much the same.
  4. FE5649B2-7664-4648-AC55-C68B6E2AF6C1
    FE5649B2-7664-4648-AC55-C68B6E2AF6C1 avatar
    4 posts
    Member since:
    Aug 2011

    Posted 25 Aug 2011 Link to this post

    I can't get it working in version 2011.2.712.40

    Please provide a working solution .
  5. 7DF664E8-B36E-4DD1-B788-9D72771FC20A
    7DF664E8-B36E-4DD1-B788-9D72771FC20A avatar
    2481 posts
    Member since:
    Dec 2019

    Posted 25 Aug 2011 Link to this post

    Hi Sam,

    I tested the code files with RadControls version 2011.2.712 and I did not notice any problems.

    You can find the updated archive attached to this post.

    Greetings,
    Tsvetina
    the telerik team

    Instantly find answers to your questions at the new telerik Support Center
Back to Top

This Code Library is part of the product documentation and subject to the respective product license agreement.