SethD02
SethD02

Reputation: 7

How to add a row to a Telerik RadGrid from codebehind?

Currently using a radgrid to display a singular row of counts for various categories of data.

Protected Sub rg_SystemExp_ItemDataBound(ByVal s As Object, ByVal e As GridItemEventArgs) Handles rg_SystemExp.ItemDataBound
    If TypeOf e.Item Is GridDataItem Then
        Dim Red As Integer = 0
        Dim Orange As Integer = 0
        Dim Yellow As Integer = 0
        Dim Green As Integer = 0
        Dim dataItem As GridDataItem = e.Item
        Dim myCell As TableCell = dataItem("Status")
        If myCell.Text >= 180 Then
            dataItem.BackColor = Drawing.Color.Green
            dataItem.ForeColor = Drawing.Color.White
            Green += 1
        ElseIf myCell.Text >= 120 Then
            dataItem.BackColor = Drawing.Color.Yellow
            dataItem.ForeColor = Drawing.Color.Black
            Yellow += 1
        ElseIf myCell.Text >= 90 Then
            dataItem.BackColor = Drawing.Color.Orange
            dataItem.ForeColor = Drawing.Color.White
            Orange += 1
        ElseIf myCell.Text < 90 Then
            dataItem.BackColor = Drawing.Color.Red
            dataItem.ForeColor = Drawing.Color.White
            Red += 1
        ElseIf myCell.Text = "TBD" Then
            dataItem.BackColor = Drawing.Color.Gray
            dataItem.ForeColor = Drawing.Color.Black
        End If

        //Was thinking this would be the best place for the code

        rg_StatusCounts.DataBind()
    End If
End Sub

I plan on adding a row to rg_StatusCounts based on the counts collected by the ItemDataBound method of another RadGrid, and then rebinding rg_StatusCounts. Only problem is I can't for the life of me figure out how to actually add an item to rg_StatusCounts. Is it possible within this context? Or does this need to be done in the rg_StatusCounts_ItemDataBound method? Thank you for any guidance.

rg_StatusCounts has 4 columns, one for green count, yellow count, orange count, red count

Upvotes: 0

Views: 49

Answers (1)

Priya Maheshwari
Priya Maheshwari

Reputation: 35

Yes this can be one way also add this code to a function and then call this databind within it- this way it can be reused as well.
for the variables instead rg_StatusCounts one can also have it binded using some state management technique like Session(server side) or Viewstate(client side) 
and using this it can be achieved

Upvotes: 0

Related Questions