Skip Navigation LinksHome / Community & Support / Code Library / ASP.NET and ASP.NET AJAX > Grid > Disable selection for some rows in GridClientSelectColumn conditionally

Disable selection for some rows in GridClientSelectColumn conditionally

Feed from this thread
  • Posted on Apr 16, 2007 (permalink)

    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> 
     

  • Posted on Jul 9, 2007 (permalink)

    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.

  • Posted on Feb 18, 2008 (permalink)

    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.

  • Sam avatar

    Posted on Aug 25, 2011 (permalink)

    I can't get it working in version 2011.2.712.40

    Please provide a working solution .

  • Tsvetina Tsvetina admin's avatar

    Posted on Aug 25, 2011 (permalink)

    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
    Attached files

Back to Top

Skip Navigation LinksHome / Community & Support / Code Library / ASP.NET and ASP.NET AJAX > Grid > Disable selection for some rows in GridClientSelectColumn conditionally