Access Data During DataBound event

2 posts, 1 answers
  1. ToltingColtAcres
    ToltingColtAcres avatar
    83 posts
    Member since:
    Nov 2010

    Posted 14 Dec 2010 Link to this post

    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?
  2. Answer
    Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 14 Dec 2010 Link to this post

    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.
  3. UI for ASP.NET Ajax is Ready for VS 2017
Back to Top