jump to navigation

Manipulating Datagrid Data at Runtime September 29 2005

This is by no means an official way to do things, this is a way to trick the result of a datagrid into displaying manipulated cell data.

The general theory is to hide the cell that you want to maniupulate the data of (at runtime) and replace it with a new cell containing the manipulated data.

1. First we need to use the ItemDataBound event for a datagrid. This will allow us to change data at runtime

Sub dgResults_OnDataBind( _
ByVal sender As System.Object, _
ByVal e As System.Web.UI.WebControls.DataGridItemEventArgs) _
Handles dgResults.ItemDataBound

2. Next hide the data cell that you want to manipulate

If ((itemType = ListItemType.Header) Or (itemType = ListItemType.Footer)) Then
Return
Else
e. item.cells(__MY_CELL_INDEX).visible = False
endif

3. Now inject your own cell into this position


Dim tc as new TableCell
tc.text = “This is my new data” (You’ll probably want to get this from a dataset or something)
e.item.cells.addAt(__MY_CELL_INDEX, tc)

And thats it! The old cell will be hidden and the new cell will be in its place.

Comments

Sorry comments are closed for this entry