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

RadGrid - Accessing a cell on ItemDataBound

2 Answers 662 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Brad
Top achievements
Rank 1
Brad asked on 07 Sep 2011, 03:01 AM

Hi

I have a RadGrid in which is some data. One of the columns of data is an nvarchar(MAX) filed in which there could be a little to a lot of text, at the prerogative of the user.

I'm trying find a way to read the text out of the grid, modify it to be truncated down to say the first 50 characters, and put it back in the cell.

I found this page on this site that talks about this exact issue. Alas the code here does work.

http://www.telerik.com/help/aspnet/grid/grdaccessingcellsandrows.html

The code on this page says I can read the cell value with this syntax

TableCell cell = dataItem["ColumnUniqueName"];

Alas this does not work as 'dataItem' does not exist.

I have tried this code in my grids ItemDataBound method,

protected void rgNotes_ItemDataBound(object sender, GridItemEventArgs e)
{
    if (e.Item is GridDataItem && e.Item.OwnerTableView.DataSourceID == "dsNotes")
    {
        TableCell cell = dataItem["NoteText"];
    }
}

I even tried
TableCell cell = e.Item["NoteText"];

to no avail.

Anyone here have a solution to this, what should be a pretty obvious' issue?

Brad



2 Answers, 1 is accepted

Sort by
0
Accepted
Shinu
Top achievements
Rank 2
answered on 07 Sep 2011, 08:46 AM
Hello Brad,

You need to save the dataItem first.
C#:
if (e.Item is GridDataItem && e.Item.OwnerTableView.DataSourceID == "dsNotes")
{
   GridDataItem dataItem= e.Item as GridDataItem;
   TableCell cell = dataItem["NoteText"];
}

Thanks,
Shinu.
0
Brad
Top achievements
Rank 1
answered on 12 Sep 2011, 01:33 AM
Thanks Shinu.

Brad
Tags
General Discussions
Asked by
Brad
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Brad
Top achievements
Rank 1
Share this question
or