在表格行asp.net c#中添加单元格中间 [英] add cell middle of table row asp.net c#

查看:64
本文介绍了在表格行asp.net c#中添加单元格中间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个新行.在该行中,我想在第5个单元格位置添加控件.
任何想法,............

I have created one new row. in that row i want to add control in 5th cell position.
any idea,..................

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.           
       }
   }
}

推荐答案

这是有关其工作方式的示例:

This is an example on how it should work:

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


这篇关于在表格行asp.net c#中添加单元格中间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆