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

Access Data During DataBound event

1 Answer 189 Views
Grid
This is a migrated thread and some comments may be shown as answers.
ToltingColtAcres
Top achievements
Rank 2
Veteran
Iron
ToltingColtAcres asked on 14 Dec 2010, 04:28 PM
I need to access the contents of my radgrid during the databound event.

I had some code which I found online that appeared to work great:

if (e.Item is GridDataItem)
{
   GridDataItem item = (GridDataItem)e.Item;
   Hashtable values = new Hashtable();
   item.ExtractValues(values);
   switch (item["Status"].ToString())
   {
      case "Status 1":
  ...etc

This all worked just dandy until I set the Status field as a ReadOnly field (which it needs to be, since people shouldn't be editing it, it is programmatically set.

Once I changed the status to ReadOnly, it "disappeared" from the extracted values.

Can someone explain why?

I then noticed, when stepping thru the code, that *all* of the "read only" fields in the grid did not appear in the extracted values.

How does one extract all the values from the row, regardless if they are readonly or not?

1 Answer, 1 is accepted

Sort by
0
Accepted
Princy
Top achievements
Rank 2
answered on 15 Dec 2010, 05:28 AM
Hello Michael,

You can direclty take the cell value(even if it is ReadOnly) by using following code snippet .

ASPX:
<telerik:GridBoundColumn UniqueName="Status" DataField="Status"  ReadOnly="true">
</telerik:GridBoundColumn>

C#:
protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)
  {
      if (e.Item is GridDataItem)
      {
          GridDataItem item = (GridDataItem)e.Item;
          string status=item["Status"].Text;
      }
  }

Also refer the following documentation.
Accessing cells and rows

Thanks,
Princy.
Tags
Grid
Asked by
ToltingColtAcres
Top achievements
Rank 2
Veteran
Iron
Answers by
Princy
Top achievements
Rank 2
Share this question
or