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

Find a control of an edit form in item command event

7 Answers 252 Views
Grid
This is a migrated thread and some comments may be shown as answers.
William
Top achievements
Rank 1
William asked on 23 Feb 2009, 07:31 PM
Hi,

I have a grid with an edit form with textboxes that I need to disable based on a button that is clicked in the form. I'm wondering if there is a way to find the textboxes in the itemcommand events that get triggered by the buttons?

I've been trying to use something like:

 

Private Sub RadGrid2_ItemCommand(ByVal source As Object, ByVal e As Telerik.WebControls.GridCommandEventArgs) Handles RadGrid2.ItemCommand

 

 

If e.CommandName = "TimeInOutTextboxes" Then

 

 

Dim editedItem As GridEditableItem = CType(e.Item, GridEditableItem)

 

 

Dim txtTimeIn As TextBox = DirectCast(editedItem.FindControl("txtTimeIn"), TextBox)

 

txtTimeIn.Enabled =

False

 

 

End If

but an error is thrown at "txtTimeIn.Enabled = False" because the control is not being found

Thanks


 

7 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 24 Feb 2009, 05:20 AM
Hi William,

Try the following code snippets and see whether its working fine for you.

VB:
Protected Sub RadGrid1_ItemCommand(ByVal source As ObjectByVal e As GridCommandEventArgs) 
    If e.CommandName = "TimeInOutTextboxes" Then 
        Dim editedItem As GridEditableItem = DirectCast(e.Item, GridEditableItem) 
        Dim txtTimeIn As TextBox = DirectCast(DirectCast((editedItem), Telerik.Web.UI.GridDataItem).EditFormItem.FindControl("txtTimeIn"), TextBox) 
        txtTimeIn.Enabled = False 
    End If 
End Sub 

Thanks,
Shinu.
0
William
Top achievements
Rank 1
answered on 24 Feb 2009, 02:04 PM
Thanks a lot Shinu, but I'm getting an error in this line?:
DirectCast
(DirectCast((editedItem), Telerik.Web.UI.GridDataItem).EditFormItem.FindControl("txtTimeIn"), TextBox)

The error is :
'Telerik.WebControls.GridEditableItem' cannot be converted to 'Telerik.Web.UI.GridDataItem'.

Thanks again,
 William
0
Accepted
Princy
Top achievements
Rank 2
answered on 24 Feb 2009, 02:37 PM
Hi William,

Try the below code snippets for accesing the textbox inside form template.

VB:
Protected Sub RadGrid1_ItemCommand(ByVal source As ObjectByVal e As GridCommandEventArgs)  
    If e.CommandName = "TimeInOutTextboxes" Then 
        Dim editedItem As GridEditableItem = DirectCast(TryCast((e.CommandSource), Button).NamingContainer, GridEditableItem)  
        Dim txtName As TextBox = DirectCast(editedItem.FindControl("txtTimeIn"), TextBox)  
    End If 
End Sub 

Thanks,
Princy.
0
William
Top achievements
Rank 1
answered on 24 Feb 2009, 04:10 PM
That works great Princy. Thanks! 
0
srinivas
Top achievements
Rank 1
answered on 10 Dec 2011, 06:48 AM
Can you post the same code in c#
0
Shinu
Top achievements
Rank 2
answered on 12 Dec 2011, 05:09 AM
Hello Srinivas,

Here is the sample code in c#.
c#:
protected void RadGrid1_ItemCommand(object source, GridCommandEventArgs e)
{
 if (e.CommandName == "TimeInOutTextboxes")
  {
    GridEditableItem editedItem = (GridEditableItem)((e.CommandSource) as Button).NamingContainer;
    TextBox txtName = (TextBox)editedItem.FindControl("txtTimeIn");
   }
}
Here is the link for code converter.
http://converter.telerik.com/

-Shinu.
0
Beth
Top achievements
Rank 1
answered on 28 Sep 2016, 12:00 AM
Thank you, your code helped me a great deal!
Tags
Grid
Asked by
William
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
William
Top achievements
Rank 1
Princy
Top achievements
Rank 2
srinivas
Top achievements
Rank 1
Beth
Top achievements
Rank 1
Share this question
or