本来是想记录下来访者ip的,结果搞半天还是错的,错误“未能在 ControlParameter“ipaddress”中找到控件“_page”。”<%@ Page Language="C#" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><script runat="server">
public string address
{
get { return Request.UserHostAddress; }
}
</script><html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:FormView ID="FormView1" runat="server" DataSourceID="SqlDataSource1" EnableModelValidation="True" DefaultMode="Insert">
<InsertItemTemplate>
名字:<asp:TextBox ID="TextBox1" Text='<%# Bind("name") %>' runat="server" /><br />
内容:<asp:TextBox ID="TextBox2" TextMode="MultiLine" Text='<%# Bind("comments") %>' runat="server" />
<asp:Button ID="Button1" runat="server" Text="提交留言" CommandName="Insert" />
</InsertItemTemplate>
</asp:FormView>
<br />
<br />
<br />
<asp:GridView ID="GridView1" runat="server" DataSourceID="SqlDataSource1"
EnableModelValidation="True">
</asp:GridView>
<br />
<br />
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConflictDetection="CompareAllValues"
ConnectionString="<%$ ConnectionStrings:filmConnectionString %>"
InsertCommand="insert Guestbook(name,comments,ipaddress) values(@name,@comments,@address)"
SelectCommand="SELECT * FROM [GuestBook]" >
<InsertParameters>
<asp:Parameter Name="name" Type="String" />
<asp:Parameter Name="comments" Type="String" />
<asp:ControlParameter Name="ipaddress" ControlID="_page" PropertyName="address" />
</InsertParameters>
</asp:SqlDataSource>
</div>
</form>
</body>
</html>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><script runat="server">
public string address
{
get { return Request.UserHostAddress; }
}
</script><html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:FormView ID="FormView1" runat="server" DataSourceID="SqlDataSource1" EnableModelValidation="True" DefaultMode="Insert">
<InsertItemTemplate>
名字:<asp:TextBox ID="TextBox1" Text='<%# Bind("name") %>' runat="server" /><br />
内容:<asp:TextBox ID="TextBox2" TextMode="MultiLine" Text='<%# Bind("comments") %>' runat="server" />
<asp:Button ID="Button1" runat="server" Text="提交留言" CommandName="Insert" />
</InsertItemTemplate>
</asp:FormView>
<br />
<br />
<br />
<asp:GridView ID="GridView1" runat="server" DataSourceID="SqlDataSource1"
EnableModelValidation="True">
</asp:GridView>
<br />
<br />
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConflictDetection="CompareAllValues"
ConnectionString="<%$ ConnectionStrings:filmConnectionString %>"
InsertCommand="insert Guestbook(name,comments,ipaddress) values(@name,@comments,@address)"
SelectCommand="SELECT * FROM [GuestBook]" >
<InsertParameters>
<asp:Parameter Name="name" Type="String" />
<asp:Parameter Name="comments" Type="String" />
<asp:ControlParameter Name="ipaddress" ControlID="_page" PropertyName="address" />
</InsertParameters>
</asp:SqlDataSource>
</div>
</form>
</body>
</html>
<asp:TextBox ID="txtId" runat="server"></asp:TextBox>
_page不存在
PropertyName="address" />
我用的是VS2010,靠,如果是__(这个怎么是两_),就会提示必须声明标量变量 "@IPAdress"。