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

Finding GridBoundControl in Command event

1 Answer 72 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Phil
Top achievements
Rank 2
Phil asked on 22 Feb 2009, 03:17 AM
Hi
I am in the grid Command event and I can not cast to GridBoundControl:

Protected Sub RadGrid1_UpdateCommand(ByVal source As Object, ByVal e As Telerik.Web.UI.GridCommandEventArgs)  
    Dim _flg As GridBoundColumn = CType(e.Item.FindControl("flgColumn"), GridBoundColumn)  
End Sub  
 
Says: Value of type 'System.Web.UI.Control' cannot be converted to 'Telerik.Web.UI.GridBoundColumn'.  I am able to find templated controls this way but how do I find the Bound controls?

1 Answer, 1 is accepted

Sort by
0
Accepted
Princy
Top achievements
Rank 2
answered on 23 Feb 2009, 04:17 AM
Hello Phil,

I suppose you are trying to access the default TextBox for a GridBoundColumn when the grid is in EditMode. If thats the case, you can access the TextBox for the column as shown below:
aspx:
 <telerik:GridBoundColumn DataField="ProductName" UniqueName="ProductName" HeaderText="ProductName"></telerik:GridBoundColumn> 

vb:
 Protected Sub RadGrid1_UpdateCommand(ByVal source As Object, ByVal e As GridCommandEventArgs) 
     If TypeOf e.Item Is GridEditableItem AndAlso e.Item.IsInEditMode Then 
         Dim editItem As GridEditableItem = DirectCast(e.Item, GridEditableItem) 
         Dim txtbx As TextBox = DirectCast(editItem("ProductName").Controls(0), TextBox) 
     End If 
 End Sub 

whereas, if you are trying to access the GridBoundColumn in the UpdateCommand, try out the following code:
vb:
     Protected Sub RadGrid1_UpdateCommand(ByVal source As Object, ByVal e As GridCommandEventArgs) 
         
         Dim column As GridBoundColumn = DirectCast(RadGrid1.MasterTableView.GetColumn("ProductName"), GridBoundColumn) 
         
     End Sub 

-Princy.
Tags
Grid
Asked by
Phil
Top achievements
Rank 2
Answers by
Princy
Top achievements
Rank 2
Share this question
or