3

我正在尝试将图像添加到我通过后面的代码动态创建的表中。但是,图像不会添加到单元格中。我发现的所有其他代码都在谈论与 table() 不同的 htmltable;

public partial class Children_nihul_1 : System.Web.UI.Page
{
    protected string mychildrenlist;

    protected void Page_Init(object sender, EventArgs e)
    {
        var cases = new List<string>();
        System.Web.UI.WebControls.Image myGamepic1 = new System.Web.UI.WebControls.Image();
       // var myGamepic1 = new Image();
        myGamepic1.ImageUrl = "~/img/inner-page/Game1.png";
        myGamepic1.Height = 30;

//这部分只是从数据库中调用数据-与问题无关。/

        DataSet ds = new DataSet();
        string x = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + Server.MapPath("./App_Data/DatabaseGames.accdb") + ";";
        string y = "select * from Students";

        mySql myq = new mySql();
        ds = myq.sqlRet(x, y);
        rowlist = ds.Tables[0].Rows.Count;

        for (int i = 0; i < rowlist; ++i)
        {
            cases.Add(ds.Tables[0].Rows[i][1].ToString()); 
        }

//我的表创建

        Table table = new Table();
        table.BorderStyle = BorderStyle.None;

        //Add Header Row
        TableRow row = new TableRow();
        TableHeaderCell headerCell = new TableHeaderCell();
        headerCell.Text = "aaa";

        row.Controls.Add(headerCell);
        headerCell = new TableHeaderCell();
        headerCell.Text = "ccc";
        row.Controls.Add(headerCell);

        table.Controls.Add(row);

        for (int i = 0; i < rowlist; ++i)
        {
            //Add DataRow
            row = new TableRow();
            TableCell cell = new TableCell();
            cell.Text = cases[i];
            row.Controls.Add(cell);

            cell = new TableCell();
            cell.Controls.Add(myGamepic1);

            row.Controls.Add(cell);

            table.Controls.Add(row);
        }

        Panel1.Controls.Add(table);
        Panel1.Controls.Add(myGamepic1);
    }

}
4

1 回答 1

3

尝试这样的事情。在使用后面的代码添加图像动态时为我工作。

cell11.Text = string.Format("<img src='images/close_icon.png' />");
于 2015-06-24T07:38:08.720 回答