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

Change contents of grid if column name is some value

1 Answer 48 Views
Grid
This is a migrated thread and some comments may be shown as answers.
pmwhelan
Top achievements
Rank 1
pmwhelan asked on 19 Jul 2010, 09:35 AM
Hi
I have a Telerik RadGrid and I want to change the cells of a column if the column name is a certain value.

For example if the column name is 'date_comparison_1' the I do not want any cells to contain a minus number.

So what I was hoping to do was...

Protected

 

Sub rgChangeRequests_ItemDataBound(ByVal sender As Object, ByVal e As Telerik.WebControls.GridItemEventArgs) Handles rgChangeRequests.ItemDataBound

 

 


 

 

If

 

e.Item.ItemType = Telerik.WebControls.GridItemType.Header Then

 

 

 

 

 

'If e.Item.ItemType = ListItemType.Header Then

 

 

 

 

 

Dim dg As DataGrid = TryCast(sender, DataGrid)

 

 

Dim col As DataGridColumn

 

 

Dim index As New Integer

 

 

 

 

 

For index = 0 To dg.Columns.Count - 1

 

 

If (col.HeaderText = "'date_comparison_1") Then

 

 

 

 

 

End If

 

 

 

 

 

Next

 

 

 

 

 

End If

 

 

 

 

 

 

End Sub

But I get an Object Reference error pointing to this line ...

 

For

 

index = 0 To dg.Columns.Count - 1

 



Any ideas?

thanks

1 Answer, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 19 Jul 2010, 12:26 PM
Hello,

You can easily achieve this by checking whether the cell value is negative or not. If it is negative change its sign. Check out the sample code below.

VB.Net:
Protected Sub RadGrid1_ItemDataBound(sender As Object, e As GridItemEventArgs)
    If TypeOf e.Item Is GridDataItem Then
        Dim item As GridDataItem = DirectCast(e.Item, GridDataItem)
        Dim value As Int64 = Convert.ToInt64(item("date_comparison_1").Text)
        If value < 0 Then
            value = Math.Abs(id)
            item("date_comparison_1").Text = value.ToString()
        End If
    End If
End Sub

Thanks,
Princy.
Tags
Grid
Asked by
pmwhelan
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Share this question
or