Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Shaun E on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Use Existing Object by String Name

Status
Not open for further replies.

DFatCat

Programmer
Nov 2, 2001
5
US
I am trying to use one function to handle a SelectedIndexChanged event for 5 radio button groups that correspond to 5 populated Datagrids. The radio buttons have a choice of 5,10 25 for a datagrid.pagesize.

I am having trouble trying to find a way to pass the name of the existing datagrid object to the function and to have it assign its the appropriate datasource, pagesize and rebind.

I found a post with this ControlFromName Function and have tried to use it but it fails with s SystemNullException in the function. Please bear with my lack of knowledge on this, reflection and some of this heavy programming is new to me. Here i my code blurb and the function as I have it. I did change it to use WebControl instead of Control since this is on as aspx page.

Thanks for any help. Damon

Dim dv As DataView
Dim dg As DataGrid
dg = CType(ControlFromName("dgToH1"), DataGrid)
dg.DataSource = dv
dg.DataBind()

Private Function ControlFromName(ByVal name As String) As WebControl
Dim o As Object
o = Me.GetType().GetField(name, Reflection.BindingFlags.Public Or _
Reflection.BindingFlags.NonPublic Or _
Reflection.BindingFlags.Instance Or _
Reflection.BindingFlags.IgnoreCase).GetValue(Me)

Return (CType(o, WebControl))
End Function
 
Thanks, actually I did just found that and got it to work. Thanks a lot.

Damon
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top