Reply
Dynamic Tablerow
Old 04-12-2007, 03:12 AM Dynamic Tablerow
Average Talker

Posts: 22
Here's what I want to do: I created an ASP:Table and now I want to add rows dynamically using TableRow. Thing is I want to have 3 pics on every row, which means that there must be a new tablerow every time the integer iced is a number that can be divided by 3 (iced % 3).

The code below would be simple and straightforward, but one of the problems with C# is that it doesn't recognize the TableRow tRow = new Table(); outside if {}, and if I declare TableRow outside the if, all I get is one tablerow for all the pictures (if it is declared above while{} ), or a tablerow for all pics with number divisible by 3 (if declared inside the while but outside the if).

How do I solve this problem?

while (myReader.Read())
{

if (iced ==1 || (iced%3) == 0)
{
contents = contents + iced.ToString();
Label1.Text = contents.ToString();
TableRow tRow = new TableRow();
value1.Rows.Add(tRow);
}

TableCell tCell = new TableCell();
tCell.Text = myReader.GetString(1);
tRow.Cells.Add(tCell);


iced++;
}

__________________________________________________ ___________________
http://www.carbotek.org

Last edited by rpcarnell : 04-12-2007 at 03:14 AM.
rpcarnell is offline
Reply With Quote
View Public Profile
 
When You Register, These Ads Go Away!
     
Old 04-12-2007, 03:34 AM Re: Dynamic Tablerow
ForrestCroce's Avatar
Half Man, Half Amazing

Posts: 3,025
Name: Forrest Croce
Location: Seattle, WA
Declare tRow above the if statement, but instead of creating a new row, set it to value1.Rows[value1.Rows.Count - 1]. Or, declare tRow outside the while loop and set it to null. The first time your loop runs it should create a new row ( 0 % 3 = 0 ), then on the next iteration, tRow will have the same value as last time.
ForrestCroce is offline
Reply With Quote
View Public Profile Visit ForrestCroce's homepage!
 
Reply     « Reply to Dynamic Tablerow
 

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off




   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML

 


Page generated in 0.11837 seconds with 13 queries