How do I loop this in a FOR loop

I

iHavAQuestion

I have a textbox control in each row of the table and I need to display it
dynamically
In the first row of the table it is txtSample1 and in the second row it is
txtSample2

The below code is not working

for (int i = 0; i < ddlHowMany.SelectedIndex ; i++)
{
UserTable.Rows.FindControl("(txtSample)+(i)").Visible = true;
}

Plz help me out..
 
I

iHavAQuestion

Though I start from one the following code dosent work
UserTable.Rows.FindControl("(txtSample)+(i)").Visible = true;

I am not able to concatinate txtSample with " i " in the loop.

Any gusses.




Mark Rae said:
In the first row of the table it is txtSample1
The below code is not working

for (int i = 0; i < ddlHowMany.SelectedIndex ; i++)
{
UserTable.Rows.FindControl("(txtSample)+(i)").Visible = true;
}

Plz help me out..


First time round, the code is looking for a control called txtSample0 which,
as you have described it, won't exist...
 
D

David

UserTable.Rows.FindControl("txtSample" + i).Visible = true;

Your txtSample was inside brackets and the whole lot was inside quotes, so
you were literally looking for a control called (txtSample)+(i)



--
Best regards,
Dave Colliver.
http://www.AshfieldFOCUS.com
~~
http://www.FOCUSPortals.com - Local franchises available
iHavAQuestion said:
Though I start from one the following code dosent work
UserTable.Rows.FindControl("(txtSample)+(i)").Visible = true;

I am not able to concatinate txtSample with " i " in the loop.

Any gusses.




Mark Rae said:
message
In the first row of the table it is txtSample1
The below code is not working

for (int i = 0; i < ddlHowMany.SelectedIndex ; i++)
{
UserTable.Rows.FindControl("(txtSample)+(i)").Visible = true;
}

Plz help me out..


First time round, the code is looking for a control called txtSample0
which,
as you have described it, won't exist...
 
P

Peter Bromberg [C# MVP]

I'm only guessing that this code will even work (the way you have it) but if
the first one is "txtSample1" then you would need this:

UserTable.Rows.FindControl("(txtSample"+(i+1).ToString() ).Visible =
true;

--Peter
 
D

David

You should be ashamed of yourself Peter... you missed a closing bracket
somewhere... :)

(Mind you, it won't actually do anything, as the bracket is inside a quoted
string, but even then, if it is called txtSample1, it won't be found with
(txtSample1 as your string. )

--
Best regards,
Dave Colliver.
http://www.AshfieldFOCUS.com
~~
http://www.FOCUSPortals.com - Local franchises available


Peter Bromberg said:
I'm only guessing that this code will even work (the way you have it) but
if the first one is "txtSample1" then you would need this:

UserTable.Rows.FindControl("(txtSample"+(i+1).ToString() ).Visible =
true;

--Peter

iHavAQuestion said:
I have a textbox control in each row of the table and I need to display
it
dynamically
In the first row of the table it is txtSample1 and in the second row it
is
txtSample2

The below code is not working

for (int i = 0; i < ddlHowMany.SelectedIndex ; i++)
{
UserTable.Rows.FindControl("(txtSample)+(i)").Visible = true;
}

Plz help me out..

 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top