Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/284.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/86.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/templates/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 将图像动态添加到html表中_C#_Html_Asp.net_Html Table - Fatal编程技术网

C# 将图像动态添加到html表中

C# 将图像动态添加到html表中,c#,html,asp.net,html-table,C#,Html,Asp.net,Html Table,我正在尝试将一个图像动态添加到表中,但它没有发生。。。 此外,当我将图像添加到单元格中时,会显示一条错误消息: 无法获取的内部内容,因为内容不是文本 if(filteredFileList.Count!=0&&filteredFileList!=null){ imgProduct.ImageUrl=Server.MapPath(@“/ysyp/Images/Products/”)+filteredFileList[0]。名称; 行数=1; columnCount=filteredFileList

我正在尝试将一个图像动态添加到表中,但它没有发生。。。 此外,当我将图像添加到单元格中时,会显示一条错误消息:

无法获取的内部内容,因为内容不是文本

if(filteredFileList.Count!=0&&filteredFileList!=null){
imgProduct.ImageUrl=Server.MapPath(@“/ysyp/Images/Products/”)+filteredFileList[0]。名称;
行数=1;
columnCount=filteredFileList.Count;
试一试{
HtmlTable tbProductImage=新的HtmlTable();
HtmlTableRow trImageRow=新的HtmlTableRow();
对于(int j=0;jtbProductImage.Controls.Add(trImageRow);//您不应该使用
控件。添加
,使用
行。添加
,请尝试以下操作:

tbProductImage.Rows.Add(trImageRow);
但我不确定这是否能解决您的问题。

试试这个:

tbProductImage.Rows.Add(trImageRow);
HtmlTable tbProductImage = new HtmlTable();
HtmlTableRow trImageRow = new HtmlTableRow();
for (int j = 0; j < columnCount; j++)
{
    if (filteredFileList.Count != 0)
    {

        HtmlTableCell tdImageCell = new HtmlTableCell();
        Image imageProduct = new Image();
        imageProduct.ID = "id";
        imageProduct.ImageUrl = "url";
        tdImageCell.Controls.Add(imageProduct);
        trImageRow.Cells.Add(tdImageCell);
    }
}
tbProductImage.Rows.Add(trImageRow);
tbProductImage
是一个
HtmlTable
。如果要将
HtmlTableRow
添加到表中,则需要将其添加到
集合中。将其添加到
控件
集合将显示当前看到的错误。因此,将代码从
控件
更改为
我会给你你需要的


同样的情况也适用于向行中添加单元格。在上面的几行中,您希望将
trImageRow.Controls.Add(tdImageRow);
替换为
trImageRow.Cells.Add(tdImageRow);

向行中添加单元格,然后向单元格中添加控件

我们做这种事

Dim r As TableRow
    Dim c As TableCell
    Dim lit As Literal

    Me.displayTable.Rows.Clear()

    r = AddRow(Me.displayTable, 0)
    c = AddCell(r, 100)

    lit = New Literal
    lit.Text = "Thank you for registering your interest."
    c.Controls.Add(lit)
表、行和单元格对象来自
System.Web.UI.WebControls
命名空间,但它们呈现为HTML表。

尝试以下操作:

tbProductImage.Rows.Add(trImageRow);
HtmlTable tbProductImage = new HtmlTable();
HtmlTableRow trImageRow = new HtmlTableRow();
for (int j = 0; j < columnCount; j++)
{
    if (filteredFileList.Count != 0)
    {

        HtmlTableCell tdImageCell = new HtmlTableCell();
        Image imageProduct = new Image();
        imageProduct.ID = "id";
        imageProduct.ImageUrl = "url";
        tdImageCell.Controls.Add(imageProduct);
        trImageRow.Cells.Add(tdImageCell);
    }
}
tbProductImage.Rows.Add(trImageRow);
HtmlTable tbProductImage=new HtmlTable();
HtmlTableRow trImageRow=新的HtmlTableRow();
对于(int j=0;j
您正试图将图像添加到
表格行(
TR
)中,这将不起作用,因为
TR
s只能包含
表格单元格(
TD
)。 您正在尝试将行直接添加到表中,而不是添加到表的
集合中:

方法是:

  • 换一排
  • 制造新的电池
  • 将图像添加到新单元格
  • 将新单元格添加到新行
  • 向表中添加新行(通过表的
    连接)
  • 编辑:对不起,我的视力不是以前的样子-年老和深夜:-(

    我认为您的代码是非常规的,因为您没有将行添加到表的行集合:


    tbProductImage.Controls.Add(trImageRow);//thx但行中有错误:tdImageRow.Controls.Add(imageProduct);无法获取的内部内容,因为内容不是文字。我不理解Serim。如果您在那里遇到错误,请更改您的问题。您写道,您在tbProductImage.Controls.Add(trImageRow)中遇到错误;您不能将tablerow作为控件添加到表中。如果您寻求帮助,请澄清您的问题!没有错误,代码是明确的,我知道,因为相同的代码在另一页上可以清楚地工作…thx但错误在第行:tdImageRow.Controls.add(imageProduct);无法获取的内部内容,因为内容不是文字。我不理解我添加了更多的解释,以及一个类似的建议,用于修复将单元格添加到行中的行中的上述代码。thx但我已经这样做了,但我的问题不在于此,还有htmlcell innertext和innerhtml属性…我的不起作用,因为你确定吗?我测试了我的代码,它对我有效。如果它给了你一个错误,我相信错误一定在你的问题的代码块之外。我知道我写了相同的代码另一页它有效,但我试图使工作代码向上…我不明白到底发生了什么。。。。