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

Controlling text in columns in edit mode

1 Answer 58 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Lance
Top achievements
Rank 1
Lance asked on 09 Aug 2010, 11:06 PM
I have a column with dynamic values that I am setting at run time in the Item_DataBound event like so:

Private Sub rgDefects_ItemDataBound(ByVal sender As Object, ByVal e As Telerik.Web.UI.GridItemEventArgs) Handles rgDefects.ItemDataBound
    'don't process anything other than data rows
    If e.Item.ItemType = GridItemType.Item OrElse e.Item.ItemType = GridItemType.AlternatingItem Then
        With DirectCast(e.Item, Telerik.Web.UI.GridDataItem)
            'set the UOM_Text based upon the UM based upon the UM
            .Item("UM").Text = Measure.DisplayUoM(UnitType.Linear, UserAccount.UnitSystemPreference)
        End With
    End If
End Sub

But when I edit the row, the column just displays as System.Data.DataRowView (because technically the bound column isn't bound, just change the cell contents at ItemBound).  What is the corresponding event or method I should use to control this when the row is in editmode?

1 Answer, 1 is accepted

Sort by
0
Accepted
Princy
Top achievements
Rank 2
answered on 10 Aug 2010, 08:01 AM
Hello Lance,

Check out the sample code below in which the cell value of the column 'CategoryName' changes dynamically. In order to get the value in edit mode, save the value in EditCommand event and restore the editform values in ItemDataBound event.

ASPX:
<telerik:GridBoundColumn DataField="CategoryName" HeaderText="CategoryName" UniqueName="CategoryName">
</telerik:GridBoundColumn>

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)
        If item("CategoryName").Text = "seafood" Then
                ' changing the cell value dynamically
            item("CategoryName").Text = "Changed Value"
        End If
    End If
    If TypeOf e.Item Is GridEditFormItem AndAlso e.Item.IsInEditMode Then
        Dim editItem As GridEditFormItem = DirectCast(e.Item, GridEditFormItem)
        Dim txt As TextBox = DirectCast(editItem("CategoryName").Controls(0), TextBox)
        'access the control
            ' restore the editform values
        txt.Text = newValues("CategoryName").ToString()
    End If
End Sub
 
Private newValues As New Hashtable()
Protected Sub RadGrid1_EditCommand(source As Object, e As GridCommandEventArgs)
    Dim item As GridDataItem = DirectCast(e.Item, GridDataItem)
    newValues("CategoryName") = item("CategoryName").Text
    ' save the value in Hashtable
End Sub

Hope this helps,
Princy.
Tags
Grid
Asked by
Lance
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Share this question
or