我试图动态地在表中创建图像,但似乎UpdatePanel没有更新。我有以下代码在我的。aspx页面。
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="ViewTile.aspx.cs" Inherits="ViewTile" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body runat="server">
<form id="form1" runat="server">
<div>
<asp:Image ID="tileImg" runat="server"/>
<asp:ScriptManager ID="ScriptManager1" runat="server"/>
<table>
<asp:updatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:PlaceHolder runat="server" ID="placeholder1"/>
</ContentTemplate>
</asp:updatePanel>
</table>
</div>
</form>
</body>
</html>
然后这个是aspx.cs页面
TableRow imageRow = new TableRow();
for (int rowItr = 0; rowItr < 3; rowItr++)
{
for (int colItr = 0; colItr < 4; colItr++)
{
System.Web.UI.WebControls.Image image = new System.Web.UI.WebControls.Image();
image.ImageUrl = "~/ShowTile.ashx?SheetId=" + SheetGUID + "&Scale=" + 3
+ "&XCoord=" + colItr + "&YCoord=" + rowItr;
placeholder1.Controls.Add(image);
TableCell imageCell = new TableCell();
imageCell.Controls.Add(image);
imageRow.Cells.Add(imageCell);
}
placeholder1.Controls.Add(imageRow);
imageRow.Cells.Clear();
}
我知道图像被正确调用的事实,因为我已经在客户端上使用图像标记手动输出了它。任何帮助都太好了!由于
您需要首先添加Table,向其添加行,最后将表添加到placeholder1.Controls
Table tbl= new Table();
for (int rowItr = 0; rowItr < 3; rowItr++)
{
TableRow imageRow = new TableRow();
for (int colItr = 0; colItr < 4; colItr++)
{
System.Web.UI.WebControls.Image image = new System.Web.UI.WebControls.Image();
image.ImageUrl = "~/ShowTile.ashx?SheetId=" + SheetGUID + "&Scale=" + 3
+ "&XCoord=" + colItr + "&YCoord=" + rowItr;
TableCell imageCell = new TableCell();
imageRow.Cells.Add(imageCell);
}
tbl.Rows.Add(imageRow);
}
placeholder1.Controls.Add(tbl);
你可以使用javascript和Web Service来实现。
创建一个调用Web Service并获取图像url的函数,并将其附加到更新面板div