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

Row Initialization Event and Cell Values

2 Answers 187 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Dan
Top achievements
Rank 2
Dan asked on 14 Apr 2011, 02:31 PM
I'm new to Telerik controls, so I apologize if this is an easy thing that I've missed in the documentation. 

We used to use a competitor's product that allowed for modifying cell values in a Row Initialization Event.  How would I go about modifying the value in a cell through code before the grid is displayed?  I haven't been able to figure this out yet. 

2 Answers, 1 is accepted

Sort by
0
Accepted
Elliott
Top achievements
Rank 2
answered on 14 Apr 2011, 03:18 PM
hey Dan

check out the ItemDataBound event
it returns one row

e.Item is the row-but what type of row it is and which interfaces are available depends on what kind of row it is
i.e. are you in edit mode or not
I've included an example - remove the pound signs in a text field
if the item is in edit mode set focus to the qty textbox
Protected Sub rgOrderItems_ItemDataBound(ByVal sender As Object, ByVal e As Telerik.Web.UI.GridItemEventArgs) Handles rgOrderItems.ItemDataBound
    Dim gdItem As GridDataItem = Nothing
    Dim geItem As GridEditableItem = Nothing
    Dim btnDelete As LinkButton
    Dim rntbQty As RadNumericTextBox
    If TypeOf e.Item Is GridDataItem Then
        gdItem = DirectCast(e.Item, GridDataItem)
        ' hard-coded locations!
        ' export to PDF chokes on "#"'s in description
        gdItem.Cells(5).Text = gdItem.Cells(5).Text.Replace("#", "")
        btnDelete = DirectCast(gdItem.Cells(11).Controls(0), LinkButton)
        btnDelete.Attributes.Add("onclick", "return ConfirmDelete();")
    End If
    If TypeOf e.Item Is GridEditableItem And e.Item.IsInEditMode Then
        geItem = DirectCast(e.Item, GridEditableItem)
        rntbQty = CType(geItem.Cells(1).FindControl("rntbQty"), RadNumericTextBox)
        rntbQty.Focus()
    End If
End Sub
0
Dan
Top achievements
Rank 2
answered on 14 Apr 2011, 06:55 PM
Thank you!  That is exactly what I was looking for.  I had missed this part when trying to figure it out myself:

If TypeOf e.Item Is GridDataItem Then
        gdItem = DirectCast(e.Item, GridDataItem)
Tags
Grid
Asked by
Dan
Top achievements
Rank 2
Answers by
Elliott
Top achievements
Rank 2
Dan
Top achievements
Rank 2
Share this question
or