473,387 Members | 1,304 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,387 software developers and data experts.

Need a few lines of code help, will pay!

I need to figure out how to go through all of the WebControls on a form,
find all the ones that are named with a "txt" prefix (ie txtFirstName), and
then retrieve the WebControl ID, Text (value), and Tab Index and put them
into a collection or array.

I have spent all day working on this and I just can't quite figure it out. I
would appreciate any help you can give. I will happily pay $50 to the first
person who can come up with a solution that works!!!

Thanks a bunch!

Robert Johnson

Nov 17 '05 #1
3 1054
Unfortunately, that doesn't quite work. Tab Index is not a property of
LiteralControl or ResourceBasedLiteralControl. As a result, I get the
following error: Public member 'TabIndex' on type
'ResourceBasedLiteralControl' not found.

It needs to use the WebControl instead of Control.

I am still still looking for a solution and am happy to pay for it! If you
(or anyone else) has a fix, I really need one!

Thanks,

Robert

"John Knoop" <jo****@home.se> wrote in message
news:Ox*************@TK2MSFTNGP11.phx.gbl...
Wouldn't something like this work?

Dim x as object

For each x in page.controls
if left(x.id, 3) = "txt" then
'do something with x.text
end if
next x

/john

"Robert Johnson" <bu*****@internetwebzone.com> wrote in message
news:eb*************@TK2MSFTNGP12.phx.gbl...
I need to figure out how to go through all of the WebControls on a form,
find all the ones that are named with a "txt" prefix (ie txtFirstName), and
then retrieve the WebControl ID, Text (value), and Tab Index and put them into a collection or array.

I have spent all day working on this and I just can't quite figure it

out. I
would appreciate any help you can give. I will happily pay $50 to the

first
person who can come up with a solution that works!!!

Thanks a bunch!

Robert Johnson


Nov 17 '05 #2

Hi,

Here the code. I prefer to use types then text. Keep the mony ... :-)

1) Class to hold data :
class MyDat
{
public string Text;
public int TabIndex;
public MyDat(string inText,int inTabIndex)
{
Text = inText;
TabIndex = inTabIndex;
}
}

2) Form Load :
private void Page_Load(object sender, System.EventArgs e)
{

// Put user code to initialize the page here
System.Collections.Hashtable oT = new
System.Collections.Hashtable();
HtmlForm theForm = (HtmlForm)this.FindControl("WebForm3");
GetTextBoxes(theForm,oT);

}

3) recursiv function :
private void GetTextBoxes(Control Father,System.Collections.Hashtable
oT)
{
for (int i = 0 ; i< Father.Controls.Count; i++)
{
if (Father.Controls[i] is TextBox)
{
MyDat oData = new MyDat(
((TextBox)Father.Controls[i]).Text,((TextBox)Father.Controls[i]).TabInde
x);
oT.Add(((TextBox)Father.Controls[i]).ID,oData);
}
if (Father.Controls.Count > 0)
{
GetTextBoxes(Father.Controls[i],oT);
}
}
}

Natty Gur, CTO
Dao2Com Ltd.
34th Elkalay st. Raanana
Israel , 43000
Phone Numbers:
Office: +972-(0)9-7740261
Fax: +972-(0)9-7740261
Mobile: +972-(0)58-888377
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 17 '05 #3
You have to check for the type of the control.
Here's a snippet that help. You will have to refine it
depending on what you are trying to do.

Dim ctl As Control
Dim ctlname As String
Dim tb As TextBox
Dim tbvalue As String

For Each ctl In Page.FindControl
("form1").Controls
ctlname = ctl.ID
'At this point you can also check if name starts with txt
If Ctl.GetType.ToString=
"System.Web.UI.WebControls.TextBox" Then
tb = ctl
tb.TabIndex = 1 'or whatever
tbvalue = tb.Text
End If
Next

Ofcourse if you put this code in the page_load section
the value of the text box will be nothing.
-----Original Message-----
I need to figure out how to go through all of the WebControls on a form,find all the ones that are named with a "txt" prefix (ie txtFirstName), andthen retrieve the WebControl ID, Text (value), and Tab Index and put theminto a collection or array.

I have spent all day working on this and I just can't quite figure it out. Iwould appreciate any help you can give. I will happily pay $50 to the firstperson who can come up with a solution that works!!!

Thanks a bunch!

Robert Johnson

.

Nov 17 '05 #4

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

Similar topics

11
by: Mark | last post by:
Hi, For the last 2 years I've been developing vehicle tracking/telemetric software for a company as a self employed individual. The project is quiet big, and is going to be there flagship...
3
by: JGBNS via DotNetMonster.com | last post by:
Hi, I am new to this forumand I apologize as i am not a .net programmer but we have a program being developed by a .net programmer. Nowwe have run into an ftp snag and I think it is part ftp and...
66
by: genestarwing | last post by:
QUESTION: Write a program that opens and read a text file and records how many times each word occurs in the file. Use a binary search tree modified to store both a word and the number of times it...
21
by: Johan Tibell | last post by:
I would be grateful if someone had a minute or two to review my hash table implementation. It's not yet commented but hopefully it's short and idiomatic enough to be readable. Some of the code...
20
by: mike | last post by:
I help manage a large web site, one that has over 600 html pages... It's a reference site for ham radio folks and as an example, one page indexes over 1.8 gb of on-line PDF documents. The site...
5
sammyboy78
by: sammyboy78 | last post by:
I'm trying to create a program that continuously asks for user input until the user inputs "stop" for employee name which will terminate the program. I have compiled the following code but when the...
2
by: Elaine121 | last post by:
hi i created this program for a university project but i don't know how to fix the problem. here is the program: // class public class Employee { private double Wage = 0, pay = 0; ...
7
by: rohitsripathi | last post by:
i need help writing this program... i am in college and i do not have time do this right now as i need to study for another test....but this is due tonight...i will pay $5 if you accept to do it and...
2
by: aszush | last post by:
//Title: Programming Assignment 1 //Version: //Copyright: Copyright (c) 1999 //Author: Andrew //Company: //Description: Computes employee's weekly gross and net pay....
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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.