473,394 Members | 1,706 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Use Existing Object by String Name

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

--
Message posted via http://www.dotnetmonster.com
Nov 21 '05 #1
2 1140
hi!

i've just answered this one on the french ng.. the answer is still in my
clipboard :O)
http://groups.google.com/groups?thre...TNGP10.phx.gbl

--
Best Regards
Yanick
"Damon Gravning via DotNetMonster.com" <fo***@DotNetMonster.com> a écrit
dans le message de
news:ab******************************@DotNetMonste r.com...
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

--
Message posted via http://www.dotnetmonster.com

Nov 21 '05 #2
Could you just pass the control as an object to the Function;

Function myfunction(mygrid as DataGrid)
mygrid.property...
End Function

"Zoury" wrote:
hi!

i've just answered this one on the french ng.. the answer is still in my
clipboard :O)
http://groups.google.com/groups?thre...TNGP10.phx.gbl

--
Best Regards
Yanick
"Damon Gravning via DotNetMonster.com" <fo***@DotNetMonster.com> a écrit
dans le message de
news:ab******************************@DotNetMonste r.com...
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

--
Message posted via http://www.dotnetmonster.com


Nov 21 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

25
by: Yves Glodt | last post by:
Hello, if I do this: for row in sqlsth: ________pkcolumns.append(row.strip()) ________etc without a prior:
1
by: Richard Holliingsworth | last post by:
Hello: The group has new 'standards' for online forms and I need to change the 'style' of my existing forms (A2002). Can I do this? I can't find a way using the GUI or the properties. ...
1
by: Brent Jenny | last post by:
I have an existing xml file taht looks like this. <?xml version="1.0" encoding="utf-8" ?> <Aircraft> <WCOJOItemType type="AircraftType" > <WCJOItemCode>03</WCJOItemCode>...
5
by: Matthew | last post by:
I have a nice little Sub that saves data in a class "mySettings" to an XML file. I call it like so: Dim mySettings As mySettings = New mySettings mySettings.value1 = "someText" mySettings.value2...
0
by: Al Fatykhov | last post by:
Using MABLE logic engine with existing .NET applications. MABLE web services provide an interface to MABLE business objects and logic. Let us review some technical details of the MABLE web...
5
by: Mukesh | last post by:
Hi i want to use AJAX.net in my Existing Application I have already installed the ajax .net ..net 3.0 and using VS 2005 in the old application i have added a new web form then script manager...
13
by: =?Utf-8?B?UGV0ZXI=?= | last post by:
I want to create a new column in a datatable from two existing columns. I have no problem to create the new column using the datatable.columns.add method. The problem is the value of the new...
1
by: Allen | last post by:
I need a way to add a method to an existing instance, but be as close as possible to normal instance methods. Using 'new' module or such code as 'def addfunc(...): def helper(...) .. setattr(...)'...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.