各位帮忙解释一下,为什么下面的Label1和3都不显示出来? 是不是哪里还要设置才可以?
我百度了很久都没有找到相关的. 都只说直接放在控件属性值那里就可以了.
先谢谢各位来帮忙的朋友了.
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %><!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>
<form id="form1" runat="server">
<div>
<asp:Label ID="Label2" runat="server" Text="Labe3333"></asp:Label>
<br />
<asp:Label ID="Label1" runat="server" Text="<%# TextBox2.Text %>"></asp:Label>
<asp:Label ID="Label3" runat="server" Text="<%# 2+2 %>"></asp:Label>
<asp:TextBox ID="TextBox2" runat="server" Text="111111" ></asp:TextBox>
</div>
</form>
</body>
</html>
我百度了很久都没有找到相关的. 都只说直接放在控件属性值那里就可以了.
先谢谢各位来帮忙的朋友了.
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %><!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>
<form id="form1" runat="server">
<div>
<asp:Label ID="Label2" runat="server" Text="Labe3333"></asp:Label>
<br />
<asp:Label ID="Label1" runat="server" Text="<%# TextBox2.Text %>"></asp:Label>
<asp:Label ID="Label3" runat="server" Text="<%# 2+2 %>"></asp:Label>
<asp:TextBox ID="TextBox2" runat="server" Text="111111" ></asp:TextBox>
</div>
</form>
</body>
</html>
<asp:Label ID="Label3" runat="server" Text="<%=2+2 %>"></asp:Label>
<asp:Label ID="Label2" runat="server" Text="Labe3333"></asp:Label>
<br />
<asp:Label ID="Label1" runat="server"><%= TextBox2.Text %></asp:Label>
<br />
<asp:Label ID="Label3" runat="server"><%= (2+2).ToString() %></asp:Label>
<br />
<asp:TextBox ID="TextBox2" runat="server" Text="111111"></asp:TextBox>
</div>
确实OK了. 非常感谢啊.可是为什么网上我搜到的教程都是直接放在属性里用的啊, 比如说下面这个地址里面讲到的第四条:
http://www.cnblogs.com/yangcaogui/archive/2012/03/12/2390065.html不仅是网上,而且书里面也说 比如:<%# 1+(2*20)%> 这样是有效的...<--ASP.NET 开发实战1200例(实例189里面写的)
http://hi.baidu.com/tonny_dxf/blog/item/4fb5393e3d86682771cf6c28.html
非常感谢,我终于明白了,数据绑定的关键在于最后的 DataBind(), 前面的<%# %>只是相当于一个占位符.
而<%= %> 这种用法实际上和ASP里面的用法一样的.