关于《ASP.NET 3.5 揭秘 卷1》里的部分错误(持续更新)

来源:互联网 发布:怎么查看网络稳定性 编辑:程序博客网 时间:2024/05/22 14:04
此书第276页代码清单9-18 ShowPageControlParameter.aspx
<%@ 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 IPAddress
    {
        get { return Request.UserHostAddress; }
    }
</script>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>Show Page Control Parameter</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:FormView
            ID="frmGuestBook"
            runat="server"
            DataSourceID="srcGuestBook"
            DefaultMode="Insert">
            <InsertItemTemplate>
                <asp:Label
                    ID="lblName"
                    runat="server"
                    Text="Your Name:"
                    AssociatedControlID="txtName" />
                <asp:TextBox
                    ID="txtName"
                    Text='<%#Bind("Name") %>'
                    runat="server" />
                <br /><br />
                <asp:Label
                    ID="lblComments"
                    runat="server"
                    Text="Your Comments:"
                    AssociatedControlID="txtComments" />
                <br />
                <asp:TextBox
                    ID="txtComments"
                    Text='<%#Bind("Comments") %>'
                    TextMode="MultiLine"
                    Columns="60"
                    Rows="4"
                    runat="server" />
                <br /><br />
                <asp:Button
                    ID="btnSubmit"
                    runat="server"
                    Text="Submit"
                    CommandName="Insert" />
            </InsertItemTemplate>
        </asp:FormView>
        <hr />
        <asp:GridView
            ID="grdGuestBook"
            runat="server"
            DataSourceID="srcGuestBook" />
        <asp:SqlDataSource
            ID="srcGuestBook"
            runat="server"
            SelectCommand="SELECT * FROM GuestBook ORDER BY Id DESC"
            InsertCommand="INSERT GuestBook (IPAddress,Name,Comments) VALUES (@IPAddress,@Name,@Comments)"
            ConnectionString="<%$ ConnectionStrings:TestDB %>">
            <InsertParameters>
                <asp:ControlParameter
                    Name="IPAddress"
                    PropertyName="IPAddress"
                    ControlID="__page" />
            </InsertParameters>
        </asp:SqlDataSource>
    </div>
    </form>
</body>
</html>
 
红色部分为遗漏部分,特别指出绿色部分的值里是两个底杠。
原创粉丝点击