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

[Solved] Change DataItem

4 Answers 124 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Zed
Top achievements
Rank 1
Zed asked on 13 Oct 2009, 01:32 PM
I have a name in ItemDataBound event I want to shorten.  When I do MyObj dataitem = (MyObj)e.Item.DataItem
dataitem.MyField = dataitem.Myfield.Substring(0,5) It does not save and it is not changed when I look at the grid. Maybe I am supposed to be doing this somewhere else (another grid event) or some other way.

4 Answers, 1 is accepted

Sort by
0
Thomas Salt
Top achievements
Rank 1
answered on 13 Oct 2009, 01:35 PM
Try using e.Item.Cells(2).Text = e.Item.Cells(2).Text.Substring(0,5);

'replacing "2" with the corresponding column index to your data field.
0
Zed
Top achievements
Rank 1
answered on 13 Oct 2009, 01:45 PM
If the column indexing changes then the code will break.  Is there a way to connect the column index to the  data or vice versa?
0
Thomas Salt
Top achievements
Rank 1
answered on 13 Oct 2009, 02:05 PM
i believe it's

GridDataItem myItem = (GridDataItem)e.Item;
myItem["myColumn"].Text;
0
Princy
Top achievements
Rank 2
answered on 14 Oct 2009, 05:45 AM
Hello Zed,

You can access the cells for a particular row in the grid using the UniqueName property of the column to which the cell belongs to. Here's a help document on how to access cells using the Column UniqueName property:
Accessing cells and rows

Thanks
Princy.
Tags
Grid
Asked by
Zed
Top achievements
Rank 1
Answers by
Thomas Salt
Top achievements
Rank 1
Zed
Top achievements
Rank 1
Princy
Top achievements
Rank 2
Share this question
or