用 <%内嵌代码%>
比如 :
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>内嵌代码的用法</title>
</head>
<body>
<form id="form1" runat="server">
<%if(DateTime.Now.Hour<12)%>
上午好!
<%else%>
下午好!
</form>
</body>
</html>
问 :
<table border="1" style="width: 545px; height: 188px">
<tr>
<td>
<asp:Label ID="BODYLabel" runat="server" Text= <%# Eval("BODY") %> ></asp:Label></td>
</tr>
</table>
如果 RE_BODY不等于空那么显示下面的回复内容, // 这句话怎么写?
<table border="1" style="width: 543px; height: 143px">
<tr>
<td>
<asp:Label ID="RE_BODYLabel" runat="server" Text= <%# Eval("RE_BODY") %> ></asp:Label></td>
</tr>
</table>
回答:
ASP.NET推荐是这样写:
<table border="1" style="width: 545px; height: 188px">
<tr>
<td>
<asp:Label ID="BODYLabel" runat="server" Text= <%# Eval("BODY") %> ></asp:Label></td>
</tr>
</table>
<table border="1" style="width: 543px; height: 143px" runat="server" Visibly= <%# Eval("RE_BODY") != null %> >
<tr>
<td>
<asp:Label ID="RE_BODYLabel" runat="server" Text= <%# Eval("RE_BODY") %> ></asp:Label></td>
</tr>
</table>