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

[Solved] Accessing controls in Edit Template

1 Answer 119 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Sam
Top achievements
Rank 1
Sam asked on 17 Jul 2009, 09:52 PM
I have a button and a texbox in the Edit Template that I need to access from the code behind. I tried the following code and it didn't work, does anyone have an example of this?

 Dim btn As Button = TryCast(sender, Button) 
        Dim btnPanel As Panel = TryCast(btn.Parent, Panel) 
        Dim dataItem As GridDataItem = TryCast(btnPanel.NamingContainer, GridDataItem) 
        dataItem("Button1").Enabled = False 
 
 
        Dim txt As TextBox = TryCast(sender, TextBox) 
        Dim txtPanel As Panel = TryCast(txt.Parent, Panel) 
        Dim dtItem As GridDataItem = TryCast(txtPanel.NamingContainer, GridDataItem) 
 
 
 
 
        If (Utilities.FileExists("GlobalReports\" & dtItem("txtReportFile").Text)) Then 
        'Do some stuff 
End If 

1 Answer, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 20 Jul 2009, 05:47 AM
Hello Sam,

If you want to access the textbox or any other control in the EditForm on clicking the EditButton, you can try out the following code:
vb:
Protected Sub RadGrid1_ItemDataBound(sender As Object, e As GridItemEventArgs) 
    If TypeOf e.Item Is GridEditFormItem AndAlso e.Item.IsInEditMode Then 
        Dim item As GridEditFormItem = DirectCast(e.Item, GridEditFormItem) 
        Dim txtbx As TextBox = DirectCast(item.FindControl("txtReportFile"), TextBox) 
        Dim strtxt As String = txtbx.Text 
    End If 
End Sub 

If you want to access the textbox in the EditForm on clicking a button in the EditForm itself or on TextChanged event, then you can try the following code:
vb:
Dim ctrl As Control = DirectCast(sender, Control) 
Dim editItem As GridEditableItem = DirectCast(ctrl.NamingContainer, GridEditableItem) 
Dim txtbx As TextBox = DirectCast(editItem.FindControl("txtReportFile"), TextBox) 
Dim strtxt As String = txtbx.Text 

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