Hi,
Simple question... I have a form with 3 textboxes : txt1, txt2,txt3
I have the names of those 3 textboxes stored in a db with their
cooresponding values.
txt1 , "test1"
txt2, "test2"
txt3, "test3"
My question is if I pull the 1st entry from the db, I read 'txt1' into a
variable 'x'. How do I then say x.text = "whatever" (so that I'm really
saying txt1.text = "whatever") I hope this makes sense and isn't too simple
of a question. 7 2187
Hi ar,
Well, you could loop through all your TextBoxes and grab the one you need.
Beware that the reference name cannot be used so you will have to store
'txt1' etc in either the Control.Name property or Control.Tag
string s = "txt1";
string t = "test1";
TextBox tb = null;
foreach(Control c in this.Controls)
{
if(c.Name == s)
tb = (TextBox)c;
}
tb.Text = t;
--
Happy Coding!
Morten Wennevik [C# MVP]
Hi Morten,
Thanks for the reply. For some reason when I run the code, I get 'Name' is
not a member of 'System.Web.UI.Control'
Any ideas? I know it's something simple....
"Morten Wennevik" wrote: Hi ar,
Well, you could loop through all your TextBoxes and grab the one you need. Beware that the reference name cannot be used so you will have to store 'txt1' etc in either the Control.Name property or Control.Tag
string s = "txt1"; string t = "test1"; TextBox tb = null; foreach(Control c in this.Controls) { if(c.Name == s) tb = (TextBox)c; }
tb.Text = t;
-- Happy Coding! Morten Wennevik [C# MVP]
Well, you didn't specify web so I thought you meant Windows controls.
There is no Name or Tag property in the Web controls.
You may be able to overcome this by keeping the references in an array
along with their names, or something like that.
struct Item
{
public TextBox tb;
public string Name;
public Item(TextBox t, string s)
{
tb = t;
Name = s;
}
}
ArrayList list = new ArrayList()
list.Add(new Item(txt1, "txt1");
list.Add(new Item(txt2, "txt2");
list.Add(new Item(txt3, "txt3");
foreach(Item i in list)
{
if(i.Name == "txt1")
{
i.tb.Text = "test1";
break;
}
}
PS! code is not tested
--
Happy Coding!
Morten Wennevik [C# MVP]
Ar,
Are you using VBNet or C#?
(Than I can make a little sample how to catch this easy).
Cor
VB.NET
"Cor Ligthert" wrote: Ar,
Are you using VBNet or C#? (Than I can make a little sample how to catch this easy).
Cor
ar,
This little (tested) sample needs on a webpage three textboxes with ID
Test1, Test2, Test3
\\\
Private Sub Page_Load(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles MyBase.Load
Dim frm As Control = Me.FindControl("Form1")
Dim test() As String = {"Whatever1", "Whatever2", "Whatever3"}
For Each ctr As Control In frm.Controls
If Not ctr.ID Is Nothing Then
If ctr.ID.Substring(0, 4) = "Test" Then
DirectCast(ctr, TextBox).Text = _
test(CInt(ctr.ID.Substring(4, 1)) - 1)
End If
End If
Next
End Sub
///
I hope this helps?
Cor
Thanks!
"Cor Ligthert" wrote: ar,
This little (tested) sample needs on a webpage three textboxes with ID Test1, Test2, Test3
\\\ Private Sub Page_Load(ByVal sender As System.Object, _ ByVal e As System.EventArgs) Handles MyBase.Load Dim frm As Control = Me.FindControl("Form1") Dim test() As String = {"Whatever1", "Whatever2", "Whatever3"} For Each ctr As Control In frm.Controls If Not ctr.ID Is Nothing Then If ctr.ID.Substring(0, 4) = "Test" Then DirectCast(ctr, TextBox).Text = _ test(CInt(ctr.ID.Substring(4, 1)) - 1) End If End If Next End Sub /// I hope this helps?
Cor This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Sugapablo |
last post by:
I have a dynamic form that that creates input variables named different
things based on what it reads from the database.
So, for example, it may create three fields, named ex12, ex23, and ex45...
|
by: Oren |
last post by:
Hi,
Is there a way to use the SelStart functionality in a textbox that has
more than 32,767 characters in it, when the cursor is beyond the
32,767th characterz?
SelStart is an integer, and it...
|
by: JohnR |
last post by:
I have a table with 1 row which is used to hold some application wide items
(one item per field, hence I only need 1 row).
I want to bind one of the fields to a textbox. After setting up the...
|
by: ar |
last post by:
Hi,
Simple question... I have a form with 3 textboxes : txt1, txt2,txt3
I have the names of those 3 textboxes stored in a db with their
cooresponding values.
txt1 , "test1"
txt2, "test2"...
|
by: Drew |
last post by:
I am building an application for inserting and updating one field in a
database. The database is in SQL Server and I am using Classic ASP. I have
a dropdown listbox that is populated with names,...
|
by: Allan Kim Jensen |
last post by:
Hello,
I am trying to retrieve data from a MySql database using ASP.net, and it
works fine when putting the result into a
gridview (Code provided in the end of this mail).
However, I'd like...
|
by: Mark A |
last post by:
DB2 8.2 for Linux, FP 10 (also performs the same on DB2 8.2 for Windoes, FP
11).
Using the SAMPLE database, tables EMP and EMLOYEE.
In the followng stored procedure, 2 NULL columns (COMM) are...
|
by: cyningeston |
last post by:
OS: WinXP Pro, VB/ASP/ADO.NET
I'm building a web-based supplier management application. For each supplier we are required by the FDA to track certain documents. I've managed to pull them from...
|
by: leiger |
last post by:
Hi,
I need help with this problem as soon as possible (within a couple of days).
This is the first time I have ever used Access 2007 and therefore I am having some problems - especially as I...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
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...
|
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...
|
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,...
|
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...
|
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,...
|
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...
|
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,...
|
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...
| |