473,761 Members | 9,477 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Question about control collection...

I have an ASP.NET page with 14 different text box on it that gets data from
a SQL Server database. Please see the following code.

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArg s) Handles MyBase.Load
SqlDataAdapter1 .Fill(DataSet11 )

If Not IsPostBack Then
'This works
'TextBox1.DataB ind()
'TextBox2.DataB ind()
'TextBox3.DataB ind()
'TextBox4.DataB ind()
'TextBox5.DataB ind()
'TextBox6.DataB ind()
'TextBox7.DataB ind()
'TextBox8.DataB ind()
'TextBox9.DataB ind()
'TextBox10.Data Bind()
'TextBox11.Data Bind()
'TextBox12.Data Bind()
'TextBox13.Data Bind()
'TextBox14.Data Bind()

'Why doesn't this work?
Dim c As Control

For Each c In Controls
If TypeOf c Is TextBox Then
c.DataBind()
End If
Next
End If
End Sub

Why does the top portion (that is commented out) work but the part that
loops through the collection does not? Is there something that I have to
reference gloablly? Is there something that I'm missing here?

Thanks,

-U

PS. I'm new to .NET
Nov 21 '05 #1
2 1220
Unforgiven,

Because it is a webpage, it acts a little bit else than documented, however
when in your code the toppart works, (I do not see what you bind) than this
should do the job.

I hope this helps?

Cor
\\\
Dim frm As Control = Me.FindControl( "Form1")
Dim ctl As Control
For Each ctl In frm.Controls
If TypeOf ctl Is TextBox Then
DirectCast(ctl, TextBox).databi nd
End If
Next
///
I have an ASP.NET page with 14 different text box on it that gets data from a SQL Server database. Please see the following code.

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArg s) Handles MyBase.Load
SqlDataAdapter1 .Fill(DataSet11 )

If Not IsPostBack Then
'This works
'TextBox1.DataB ind()
'TextBox2.DataB ind()
'TextBox3.DataB ind()
'TextBox4.DataB ind()
'TextBox5.DataB ind()
'TextBox6.DataB ind()
'TextBox7.DataB ind()
'TextBox8.DataB ind()
'TextBox9.DataB ind()
'TextBox10.Data Bind()
'TextBox11.Data Bind()
'TextBox12.Data Bind()
'TextBox13.Data Bind()
'TextBox14.Data Bind()

'Why doesn't this work?
Dim c As Control

For Each c In Controls
If TypeOf c Is TextBox Then
c.DataBind()
End If
Next
End If
End Sub

Why does the top portion (that is commented out) work but the part that
loops through the collection does not? Is there something that I have to
reference gloablly? Is there something that I'm missing here?

Thanks,

-U

PS. I'm new to .NET

Nov 21 '05 #2
Cor Ligthert wrote:
: Unforgiven,
:
: Because it is a webpage, it acts a little bit else than documented,
: however when in your code the toppart works, (I do not see what you
: bind) than this should do the job.
:
: I hope this helps?
:
: Cor
: \\\
: Dim frm As Control = Me.FindControl( "Form1")
: Dim ctl As Control
: For Each ctl In frm.Controls
: If TypeOf ctl Is TextBox Then
: DirectCast(ctl, TextBox).databi nd
: End If
: Next
: ///
:
:

Thanks Cor, that works. But here is something that confuses me. You have...

Dim frm As Control = Me.FindControl( "Form1")

I don't have a form called Form1. The name of the page that I have is
default.aspx. Should I replace Form1 with default.aspx or leave it as it is?
And also, why does 'Me.FindControl ("Form1")' work when I don't have a form
called 'Form1'?

Thanks,

-U

[snip]
Nov 21 '05 #3

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

Similar topics

7
371
by: John | last post by:
I have a class the reads in a file and sets the values of the file into its properties. This class is used to populate the data onto a form. This form has controls created at runtime based on user input (file values when file is opened). I was hoping to put the name of the property in the tag of each control and fire an event if the a file is open when the control is created and use the tag to get the correct property from the class. ...
2
3182
by: Brian | last post by:
NOTE ALSO POSTED IN microsoft.public.dotnet.framework.aspnet.buildingcontrols I have solved most of my Server Control Collection property issues. I wrote an HTML page that describes all of the problems that I have encountered to date and the solutions (if any) that I found. http://users.adelphia.net/~brianpclab/ServerControlCollectionIssues.htm This page also has all of the source code in a compressed file that you are free to download...
1
2726
by: Dot net work | last post by:
Hello. I have an interesting data binding scenario: I have a repeater control. It repeats a typical custom web user control. I also have a collection object, and each collection element contains various pieces of information inside a custom object, including an id field.
4
1419
by: Chuck Cobb | last post by:
I have a question regarding generics: Suppose I want to create some generic collection classes: Collection<Cats> c; Collection<Dogs> d; and both Cats and Dogs are inherited from a base class called Animals. I'd like to have a class: Collection<Animals>
1
1456
by: Chuck Cobb | last post by:
Here's one more question on this topic: I am developing a CRM system using business objects...I have used the approach we previously discussed to develop lists of business objects for the application and it works great! For example, - Class ClientInfo defines a business object for a Client - ClientInfo is inherited from BaseInfo which defines some basic item methods and interfaces such as - INotifyPropertyChanged - IEditableObject
3
1470
by: Henry | last post by:
I know it is possible to store dynamic propterties for applications in XML files. The app.config and the web.config files can be used to store AppSettings... I am just wondering how far one can go with this technique. In my case, what I am interested in doing is to store information about reports and report parameters that I might want to use in an XML file. Ideally I'd like to get to the point answer and respond to the following...
10
1968
by: mg | last post by:
I'm migrating from VB6 and have a question about using 'Using' and the best way to use it. Here is a example of a small bit of code: dbConx("open") Using CN Dim CMD As New OleDbCommand(sSQL, CN) Dim DR As OleDbDataReader = CMD.ExecuteReader()
2
1384
by: JayC | last post by:
hello all, New programmer to the .net world. I am working with VS.net 2005 using VB. So here goes. I am trying to figure out how the treeview control works from a programming perspective. I know how to populate it manually with the control properties. my question revolves around the use of the Node method creating Root-parent and the children of the parent.
10
1509
by: Rob | last post by:
I am reading a book that says that the "name" property can be altered only at design time and cannot be modified at runtime. Please explain this given the code below... If you click Button3... fred will appear as the Name of Button1, however, the handler for Button1 works still works as well... Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
3
157
by: H. S. Lahman | last post by:
Responding to siddharthkhare... Ignore Topmind and frebe. They are anti-OO P/R guys. Let's not confuse things with specific 3GL syntax. At the OOA/D level the model looks like: | 1
0
10136
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9988
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9923
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8813
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7358
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5266
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5405
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3911
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2788
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.