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

RadGrid(ItemDataBound method) Get value of cell (boolean)

2 Answers 1025 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Kaleidacare
Top achievements
Rank 1
Kaleidacare asked on 03 Feb 2011, 02:43 PM

I'm using the RadGrid contro and. In the ItemDataBound method I'm trying to get the value of a cell which is boolean and I'm receiving a FormException was unhandled by user code (String was not recognized asa valid Boolean) Error.

The only fields that get this error are the boolean fields. All other returns the text or integer with no problem. One thing that does happen is if in debug mode and I mouse over the variable I see the variable and the value (locked = false).Also if I don't conver the variable the value rturns as " " which is very strange.

Any reason how i can return a boolean value or what needs to be done so i can get the correct value without the error or  ?

protected void gridAddendum_ItemDataBound(object sender, GridItemEventArgs e)
        {
            //Is it a GridDataItem
            if (e.Item is GridDataItem)
            {
                //Get the instance of the right type
                GridDataItem dataBoundItem = e.Item as GridDataItem;

                var logid = dataBoundItem["LogId"].Text;
                var deleted = dataBoundItem["Deleted"].Text; // this is a boolean
                var Ownerid = dataBoundItem["OwnerId"].Text;
                var locked = Convert.ToBoolean(dataBoundItem["Locked"].Text); // this is a boolean
            }

        }

 

 

 

 

2 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 04 Feb 2011, 05:46 AM
Hello BJ,

If the field 'Locked' shows as a CheckBox in RadGrid, try the following approach to get the value.

C#:
if (e.Item is GridDataItem)
        {
            GridDataItem dataBoundItem = e.Item as GridDataItem;
            CheckBox chk = (CheckBox)dataBoundItem["Locked"].Controls[0];
            bool locked = chk.Checked;
        }

Thanks,
Princy.
0
Simone
Top achievements
Rank 1
answered on 20 Jun 2011, 09:45 PM

GridDataItem item = (GridDataItem)e.Item;
bool locked = Convert.ToBoolean(((DataRowView)item.DataItem)["Locked"]);
Tags
Grid
Asked by
Kaleidacare
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Simone
Top achievements
Rank 1
Share this question
or