Change contents of grid if column name is some value

2 posts, 0 answers
  1. pmwhelan
    pmwhelan avatar
    104 posts
    Member since:
    Apr 2007

    Posted 19 Jul 2010 Link to this post

    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...



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







    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












    End If







    End Sub

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




    index = 0 To dg.Columns.Count - 1


    Any ideas?


  2. Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 19 Jul 2010 Link to this post


    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.

    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

  3. DevCraft R3 2016 release webinar banner
Back to Top