Set checkbox state on GridClientSelectColumn

3 posts, 0 answers
  1. Michael Gois
    Michael Gois avatar
    17 posts
    Member since:
    Oct 2008

    Posted 24 Nov 2008 Link to this post

    Hi
    I have a datagrid with a GridClientSelectColumn. When I load page from an external source I would like to set the checked value of a particular row. I have written the following code to run on the data grid's itemDataBound event:

    protected void gridLocations_ItemDataBound(object sender, GridItemEventArgs e)
        {
            if (e.Item is GridDataItem)
            {
                GridDataItem item = e.Item as GridDataItem;
                int iLocation = (int) (Int32) item.OwnerTableView.DataKeyValues[item.ItemIndex]["location_id"];
                if (iLocation == iLocationIdToCheck)
                {
                    TableCell tc = item["colSelect"];
                    CheckBox chkSelect = tc.Controls[0] as CheckBox;
                    chkSelect.Checked = true;
                }
            }
        }

    This compiles and runs through without any exceptions, but when the grid loads, the checkbox isnt actually checked. What needs to be done to have a particular checkbox selected?

    Thanks



  2. Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 24 Nov 2008 Link to this post

    Hi,

    Try selecting the required row as shown below and see if it is working.

    CS:
    protected void gridLocations_ItemDataBound(object sender, GridItemEventArgs e) 
        { 
            if (e.Item is GridDataItem) 
            { 
                GridDataItem item = e.Item as GridDataItem; 
                int iLocation = (int) (Int32) item.OwnerTableView.DataKeyValues[item.ItemIndex]["location_id"]; 
                if (iLocation == iLocationIdToCheck) 
                { 
                   item.Selected = true;  
                } 
            } 
        } 


    Regards
    Shinu

  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Michael Gois
    Michael Gois avatar
    17 posts
    Member since:
    Oct 2008

    Posted 25 Nov 2008 Link to this post

    That did work.. Such a simple solution, I should have seen it myself!
    Thanks


Back to Top