How do I loop this in a FOR loop

  • Thread starter Thread starter iHavAQuestion
  • Start date Start date
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..
 
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...
 
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...
 
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
 
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..

 
Back
Top