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

Set checkbox state on GridClientSelectColumn

2 Answers 223 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Michael Gois
Top achievements
Rank 1
Michael Gois asked on 24 Nov 2008, 02:32 PM
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 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 25 Nov 2008, 05:45 AM
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

0
Michael Gois
Top achievements
Rank 1
answered on 25 Nov 2008, 09:09 AM
That did work.. Such a simple solution, I should have seen it myself!
Thanks


Tags
Grid
Asked by
Michael Gois
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Michael Gois
Top achievements
Rank 1
Share this question
or