2013-05-08 60 views
0

我試圖在表中動態創建圖像,但好像UpdatePanel沒有更新。我在.aspx頁面中有以下代碼。使用UpdatePanel動態添加圖像

<%@ 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(); 
} 

我知道一個事實,即圖像的調用是否正確,因爲我已經使用客戶端上的圖像標籤手動輸出它。任何幫助將是偉大的!由於

回答

1

您需要先表添加表,行添加到它最後添加到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); 
+0

任職的功能!感謝您的幫助! – 2013-05-08 04:39:18

1

爲此,您可以使用JavaScript和Web服務。

創建調用Web服務並獲取圖像的URL,並將其添加到更新面板DIV