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

Undifined grid in code behind

2 Answers 66 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Bill Noble
Top achievements
Rank 1
Bill Noble asked on 21 Jul 2008, 02:22 PM

Hello

I have explored the forums and help files, but I am unable to find an answer.

I have an application where I have a grid, which has a corresponding image button which when clicked exports the data to excel.
This works fine.

I have set this grid to edit via a Template Form.Within this edit form, I display various labels relating to the selected record.
I also have an embeded grid on this form whose data source is filtered according to the selected record, this grid has it's own related image button to enable export.

I wish to be able to click the image button on the edit form, and export this second grid. My problem is that I am unable to reference this second grid within the code behind of the onClick event of the image button.

VS2008 states that the second gid is undifined.

Any help please.!

(VS 2008 – Telerik AJAX – .NET 3.5)

Many Thanks

Bill Noble

2 Answers, 1 is accepted

Sort by
0
Vlad
Telerik team
answered on 21 Jul 2008, 03:44 PM
Hi Bill,

You can cast sender argument in click event handler to Control and using NamingContainer property you can reach GridItem. Here is an example:


Control control = ((GridItem)((Control)sender).NamingContainer).FindControl("YourControlID");

All the best,
Vlad
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
0
Bill Noble
Top achievements
Rank 1
answered on 22 Jul 2008, 10:48 AM
Thanks Vlad

I received this solution from Tech Support. and post it here for the benefit of others.

Best Regards
Bill



Protected
Sub RadGrid1_ItemCommand(ByVal source As Object, ByVal e As Telerik.Web.UI.GridCommandEventArgs) Handles RadGrid1.ItemCommand

If e.CommandName = "CustomCommandName" Then ' this is the name used for a custom command on the button

Dim ImgButton As ImageButton = CType(e.CommandSource, ImageButton)

Dim MyItem As GridEditFormItem = CType(ImgButton.NamingContainer, GridEditFormItem)

Dim grid As RadGrid = CType(MyItem.FindControl("RadGrid2"), RadGrid) 'this is the inner grid

grid.MasterTableView.ExportToExcel()

'export the inner grid to excel

End If

End Sub

Tags
Grid
Asked by
Bill Noble
Top achievements
Rank 1
Answers by
Vlad
Telerik team
Bill Noble
Top achievements
Rank 1
Share this question
or