Click here to Skip to main content
15,887,294 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have created one new row. in that row i want to add control in 5th cell position.
any idea,..................
C#
Table tab = new Table();
TableRow tr = new TableRow();
TableCell tc = new TableCell();
tc = new TableCell();
ImageButton img1 = new ImageButton();
Label lblDate = new Label();
lblDate.ID = i.ToString();
lblDate.Text = i.ToString();
img1.ID = i.ToString();
img1.ImageUrl = "Available.jpg";
img1.Width = new Unit(50);
lblDate.Width = new Unit(20);
tc.Controls.Add(lblDate);
tc.Controls.Add(img1);
for (int j = 0; j <= dayOfWeek; j++)
{
   if (j == dayOfWeek)
   {
       if (tr.Cells.Count <= 8)
       {
           tr.Cells.Add(tc);
       }
       if (tr.Cells.Count >= 8)
       {
           tr=new TableRow();
           tr.cells[dayOfWeek].controls.Add(tc); // I want to add tc in the 5th cell.           
       }
   }
}
Posted
Updated 10-Sep-12 0:15am
v2
Comments
Mario Majčica 10-Sep-12 6:23am    
First rows than cells!

And sorry why are you trying to add a cell in a cell???

1 solution

This is an example on how it should work:

C#
Table table = new Table();
Image image = new Image();

// add 5 rows
for (int i = 0; i < 4; i++)
{
    TableRow row = new TableRow();
    table.Rows.Add(row);

    // add 5 cells
    for (int j = 0; j < 4; j++)
    {
        TableCell cell = new TableCell();
        row.Cells.Add(cell);

        // add an image in cell 3

        if (j == 2)
            cell.Controls.Add(image);
    }
}



Cheers
 
Share this answer
 
Comments
oliver grace 12-Sep-12 2:07am    
Thank a lot genius....

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900