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

[Solved] Accessing a read-only databound column GridEditableItem returns nothing!

1 Answer 310 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Richard
Top achievements
Rank 2
Richard asked on 28 May 2009, 01:21 PM
Hi

I have just recently upgraded a project to AJAX Q3 2008 from the Classic 2008 version.

In the past, the code accesses read-only databound columns of a radgrid via the .text propery of the GridEditableItem (at ItemDatabound event), which would return a valid value.  However! Since the upgrade, everything has fallen to pieces!
The GridEditableItem doesn't seem to hold read-only values now in the new version. 
i.e.
This is the read-only column:
<radTS:GridBoundColumn DataField="LastName" HeaderText="LastName" ReadOnly="True" UniqueName="LastName">  
</radTS:GridBoundColumn> 

The first part of the VB code populates the radgrid rgdContact, then sets every row to Edit mode and rebinds
rgdContact.DataSource = dt 
rgdContact.DataBind()  
 
For Each GDItem As GridDataItem In rgdContact.Items  
     GDItem.Edit = True 
Next  
 
rgdContact.Rebind() 


The second part of the VB code occurs on data bind events.  If it is the rebind (every row is in edit mode) then it tries to access the read-only column.  Here is the problem where a "nbsp;" value is returned for every read-only column.
    
Private Sub rgdContact_ItemDataBound(ByVal sender As ObjectByVal e As Telerik.Web.UI.GridItemEventArgs) Handles rgdContact.ItemDataBound     
     
If TypeOf e.Item Is GridEditableItem And e.Item.IsInEditMode Then   
   Dim gridEditFormItem As GridEditableItem = CType(e.Item, GridEditableItem)     
   Dim strLastName As String = gridEditFormItem.Item("LastName").text     
   'strLastName "nbsp;" for some reason!    
End If   
 
End Sub    
 

1 Answer, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 29 May 2009, 06:40 AM
Hello Richard,

A suggestion is to set the ReadOnly Column as the DataKeyName of the gridtableview and access the value as shown below:
aspx:
<telerik:RadGrid ID="RadGrid1" AllowMultiRowEdit="true"  DataSourceID="SqlDataSource1" runat="server"  OnItemDataBound="RadGrid1_ItemDataBound" > 
  <MasterTableView EditMode="InPlace" DataKeyNames="LastName" DataSourceID="SqlDataSource1">        
         

c#:
 protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e) 
    { 
        if (e.Item is GridEditableItem && e.Item.IsInEditMode) 
        { 
            GridEditableItem editItem = (GridEditableItem)e.Item; 
            string strtxt = editItem.GetDataKeyValue("LastName").ToString(); 
        } 
    } 

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