Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

How do I loop this in a FOR loop

1 view
Skip to first unread message

iHavAQuestion

unread,
May 6, 2008, 8:52:01 PM5/6/08
to
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[i].FindControl("(txtSample)+(i)").Visible = true;
}

Plz help me out..

Mark Rae [MVP]

unread,
May 6, 2008, 9:49:04 PM5/6/08
to
"iHavAQuestion" <iHavAQ...@discussions.microsoft.com> wrote in message
news:FBD2DD26-C9A3-4019...@microsoft.com...

> 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[i].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...


--
Mark Rae
ASP.NET MVP
http://www.markrae.net

iHavAQuestion

unread,
May 6, 2008, 10:28:00 PM5/6/08
to
Though I start from one the following code dosent work

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

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

Any gusses.

David

unread,
May 7, 2008, 4:08:43 AM5/7/08
to
UserTable.Rows[i].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" <iHavAQ...@discussions.microsoft.com> wrote in message

news:3D777F62-3313-404B...@microsoft.com...

Peter Bromberg [C# MVP]

unread,
May 7, 2008, 8:02:39 PM5/7/08
to
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[i].FindControl("(txtSample"+(i+1).ToString() ).Visible =
true;

--Peter

"iHavAQuestion" <iHavAQ...@discussions.microsoft.com> wrote in message
news:FBD2DD26-C9A3-4019...@microsoft.com...

David

unread,
May 8, 2008, 3:44:18 AM5/8/08
to
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 [C# MVP]" <pbro...@nospammaam.yahoo.com> wrote in message
news:3518932A-91F1-462F...@microsoft.com...

0 new messages