2013-11-01 41 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)));