2013-11-01 40 views
0
<asp:Table ID="tbl_Main" runat="server"> 
    <asp:TableRow> 
     <asp:TableCell> 
    **<a href=""> </a>** 
     </asp:TableCell> 
    </asp:TableRow> 
</asp:Table> 

非常基本的吧?我可是從代碼填充此背後是這樣的:錨上動態創建的表

 int rowCount = myset.Tables[0].Rows.Count; 
     int cellCount = myset.Tables[0].Columns.Count; 
     for (int rowCtr = 1; rowCtr <= rowCount; rowCtr++) 
     { 
      // Create new row and add it to the table. 
      TableRow tRow = new TableRow(); 
      tbl_Main.Rows.Add(tRow); 
      for (int cellCtr = 1; cellCtr <= cellCount; cellCtr++) 
      { 
       // Create a new cell and add it to the row. 
       TableCell tCell = new TableCell(); 
       tCell.ID = BuildMyPath(rowCtr.ToString(), cellCtr.ToString()); 
       tCell.Text = "Row " + rowCtr + ", Cell " + cellCtr; 
       tRow.Cells.Add(tCell); 
      } 
     } 

正如你可以看到香港專業教育學院增加了一個ID來,我想給小區的href內有其價值的T細胞。

現在我已經嘗試過接近所有的eval表達式,但都沒有工作。 基本上我想這樣做:

<a href="<%= Eval("tCell.ID")%>"> </a> 

謝謝。

回答

0

設計:

<div id="anchor" runat="server"> 

</div> 

在後面的代碼,你必須設置:

anchor.InnerHtml="Div Content"; //Same use for <a> tag 

或任何你想設置

+0

我想避免使用g另一個div,並瞭解eval的用法 –

0

我已經解決了這個使用LiteralControl

tCell.Controls.Add(new LiteralControl(string.Format("<a href={0}>{1}</a>", myPath, textShown)));