<%# %>数据绑定语法都将被生成一个DataBoundLiteralControl类型的控件,并且在DataGrid,Repeater,DataList中多个连续的<%# %>绑定表达式只合并成一个DataBoundLiteralControl控件。
Code
<ItemTemplate>
<tr class="even">
<td width="100"><%# DataItemInfo(Container.DataItem, 1) %>
</td>
<td width="300"><%# DataItemInfo(Container.DataItem, 2) %>
<asp:DropDownList Runat="server"></asp:DropDownList>
</td>
<td width="100"><%# DataItemInfo(Container.DataItem, 3) %>
</td>
<td width="*"><a href="unit_detail.aspx?ID=<%# DataItemInfo(Container.DataItem, 1) %>">修改</a>
<asp:LinkButton CommandArgument="<%# DataItemInfo(Container.DataItem, 1) %>" OnCommand=Delete_Command Runat=server>删除</asp:LinkButton>
<a href='DUserScore.ashx?ID=<%# DataItemInfo(Container.DataItem, 1) %>'>考生成绩报表</a>
</td>
</tr>
</ItemTemplate>
<ItemTemplate>
<tr class="even">
<td width="100"><%# DataItemInfo(Container.DataItem, 1) %>
</td>
<td width="300"><%# DataItemInfo(Container.DataItem, 2) %>
<asp:DropDownList Runat="server"></asp:DropDownList>
</td>
<td width="100"><%# DataItemInfo(Container.DataItem, 3) %>
</td>
<td width="*"><a href="unit_detail.aspx?ID=<%# DataItemInfo(Container.DataItem, 1) %>">修改</a>
<asp:LinkButton CommandArgument="<%# DataItemInfo(Container.DataItem, 1) %>" OnCommand=Delete_Command Runat=server>删除</asp:LinkButton>
<a href='DUserScore.ashx?ID=<%# DataItemInfo(Container.DataItem, 1) %>'>考生成绩报表</a>
</td>
</tr>
</ItemTemplate>
后台代码:
Code
foreach(Control c in this.rpUnitlist.Items[0].Controls)
{
Response.Write(c.GetType().ToString());
DataBoundLiteralControl dblc = c as DataBoundLiteralControl;
if(dblc != null)
Response.Write(": " + HttpUtility.HtmlEncode(dblc.Text) + "<br>");
else
Response.Write("<br>");
}
foreach(Control c in this.rpUnitlist.Items[0].Controls)
{
Response.Write(c.GetType().ToString());
DataBoundLiteralControl dblc = c as DataBoundLiteralControl;
if(dblc != null)
Response.Write(": " + HttpUtility.HtmlEncode(dblc.Text) + "<br>");
else
Response.Write("<br>");
}
输出:
Code
System.Web.UI.DataBoundLiteralControl: <tr class="even"> <td width="100">070001 </td> <td width="300">广州703
System.Web.UI.WebControls.DropDownList
System.Web.UI.DataBoundLiteralControl: </td> <td width="100">070001 </td> <td width="*"><a href="unit_detail.aspx?ID=070001">修改</a>
System.Web.UI.WebControls.LinkButton
System.Web.UI.DataBoundLiteralControl: <a href='DUserScore.ashx?ID=070001'>考生成绩报表</a> </td> </tr>
System.Web.UI.DataBoundLiteralControl: <tr class="even"> <td width="100">070001 </td> <td width="300">广州703
System.Web.UI.WebControls.DropDownList
System.Web.UI.DataBoundLiteralControl: </td> <td width="100">070001 </td> <td width="*"><a href="unit_detail.aspx?ID=070001">修改</a>
System.Web.UI.WebControls.LinkButton
System.Web.UI.DataBoundLiteralControl: <a href='DUserScore.ashx?ID=070001'>考生成绩报表</a> </td> </tr>
另外,DataGrid.Items[i].DataItem属性貌似只能在DataGrid的内部事件过程中引用,其他地方引用为空