Forum Moderators: open

Message Too Old, No Replies

table cell array help

table cell array and td highest value

         

ryanoasis

6:59 pm on Mar 3, 2004 (gmt 0)

10+ Year Member



School project, I am creating td tags and adding to the tr which I add to the table while I read through my datareader.

Each time I create a new row and add it to the table. Also I create about 10 td tags. For each td I assign almost the same text. With the only difference being the datareader getvalue().

I want to create a tablecell array and loop through and populate it.

// CODE: (Shortened)


while(drTemp.Read())
{
intCtr++;
TableRow trTag = new TableRow();
TableCell tdTag0 = new TableCell(), tdTag1 = new TableCell(), tdTag2 = new TableCell() , tdTag3 = new TableCell(), tdTag4 = new TableCell() , tdTag5 = new TableCell(), tdTag6 = new TableCell() , tdTag7 = new TableCell(), tdTag8 = new TableCell() , tdTag9 = new TableCell();

// I do the FOLLOWING same code for each td (the GetValue does however change each time):

tdTag0.Text = drTemp.GetValue(0).ToString();

// after this I add all the td's to the tr tag:

trTag.Controls.Add(tdTag0);

// then add to the table:
tblResult.Controls.Add(trTag);
}


I have tried to make an array of tablecells and loop through and each time add it to the row. But I get errors like object reference not set to instance of an object.

// Here is what I am TRYING to do (while reading from the datareader):

TableCell[] td = new TableCell[8];

for(int i = 0; i < 8; i++)
{
td[i].Text = "hello";
trTag.Controls.Add(td[i]);
}

// I have an example working:

String[] arr = new String[9];
for(int i = 0; i < 9; i++)
{
arr[i] = "¦ asdlfkj ¦";
Response.Write(arr[i].ToString());
}


I think my problem is when I add the td[] array indexes to the tr.

>>The reason I want to make an array is to compare all the td's in the tr and then BOLD or something the highest value. Any ideas on this as well?

Any help or hints would be great. Thanks.

(yes I have searched for how to do this let me know if there is a url about this or something)

TheNige

9:44 pm on Mar 3, 2004 (gmt 0)

10+ Year Member



I would put the result set in a dataset and then use a Repeater or Datalist control. You can then check the dataset with a function and dataview to see if your value is the greatest and then bold it.