Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

.NET Forum


You are currently viewing our .NET Forum as a guest. Please register to participate.
Login



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

Posts: 23
Trades: 0
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 04:14 AM..
rpcarnell is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 04-12-2007, 04:34 AM Re: Dynamic Tablerow
ForrestCroce's Avatar
Half Man, Half Amazing

Posts: 3,023
Name: Forrest Croce
Location: Seattle, WA
Trades: 0
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.
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
ForrestCroce is offline
Reply With Quote
View Public Profile Visit ForrestCroce's homepage!
 
Reply     « Reply to Dynamic Tablerow
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

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

BB 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.12317 seconds with 12 queries