<%@ Page Language="C#" AutoEventWireup="true" CodeFile="newsAdminDetail.aspx.cs" Inherits="newsInsert" %><!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>
    <link href="Style.css" rel="stylesheet" type="text/css" />
<script language="javascript" type="text/javascript">
// <!CDATA[function P1_onclick() {}// ]]>
</script>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <p id="P1" class="style4" onclick="return P1_onclick()" style="left: -21px; behavior: url(newsAdmin.aspx);
            vertical-align: bottom; width: 95%; position: absolute; top: 19px; text-align: right">
            <img align="left" class="style3" src="image/newsCenter_r2_c1.jpg" />
            <a class="nav" href="news.aspx"><span style="font-size: 10pt; color: #006699">回到主页</span></a>
            &nbsp; &nbsp;<asp:LoginStatus ID="LoginStatus2" runat="server" Height="4px" LogoutAction="Redirect"
                LogoutPageUrl="~/news.aspx" Width="32px" />
            &nbsp;&nbsp;</p>
        <br />
        <br />
        <br />
        <br />
        <br />
        <br />
        <br />
        <asp:LoginView ID="LoginView1" runat="server">
            <LoggedInTemplate>
                <asp:DetailsView ID="DetailsView1" runat="server" AutoGenerateRows="False" BorderWidth="0px"
                    Caption="新闻数据管理" CellPadding="4" CellSpacing="1" CssClass="Forumline" DataKeyNames="news_id"
                    DataSourceID="SqlDataSource1" DefaultMode="Edit" Height="50px" Width="95%">
                    <RowStyle CssClass="row1" HorizontalAlign="Left" />
                    <FieldHeaderStyle CssClass="row3" Font-Bold="True" HorizontalAlign="Center" Width="80px" />
                    <Fields>
                        <asp:TemplateField HeaderText="类别">
                            <EditItemTemplate>
                                <asp:DropDownList ID="DropDownList1" runat="server" SelectedValue='<%# Bind("news_type") %>'>
                                    <asp:ListItem>政治</asp:ListItem>
                                    <asp:ListItem>经济</asp:ListItem>
                                    <asp:ListItem>文体</asp:ListItem>
                                    <asp:ListItem>生活</asp:ListItem>
                                    <asp:ListItem>其他</asp:ListItem>
                                </asp:DropDownList>
                            </EditItemTemplate>
                            <InsertItemTemplate>
                                <asp:DropDownList ID="DropDownList2" runat="server" SelectedValue='<%# Bind("news_type") %>'>
                                    <asp:ListItem>政治</asp:ListItem>
                                    <asp:ListItem>经济</asp:ListItem>
                                    <asp:ListItem>文体</asp:ListItem>
                                    <asp:ListItem>生活</asp:ListItem>
                                    <asp:ListItem>其他</asp:ListItem>
                                </asp:DropDownList>
                            </InsertItemTemplate>
                        </asp:TemplateField>
                        <asp:TemplateField HeaderText="日期">
                            <EditItemTemplate>
                                <asp:TextBox ID="TextBox1" runat="server" Text='<%# Now() %>'></asp:TextBox>
                            </EditItemTemplate>
                            <InsertItemTemplate>
                                <asp:Label ID="Label1" runat="server" Text='<%# Bind("news_date") %>'></asp:Label>
                            </InsertItemTemplate>
                        </asp:TemplateField>
                        <asp:BoundField DataField="news_subject" HeaderText="标题" SortExpression="news_subject" />
                        <asp:BoundField DataField="news_editor" HeaderText="编辑者" SortExpression="news_editor" />
                        <asp:TemplateField HeaderText="内容">
                            <EditItemTemplate>
                                <asp:TextBox ID="TextBox2" runat="server" Height="100px" Text='<%# Bind("news_content") %>'
                                    TextMode="MultiLine" Width="450px"></asp:TextBox>
                            </EditItemTemplate>
                            <InsertItemTemplate>
                                <asp:TextBox ID="TextBox3" runat="server" Height="100px" Text='<%# Bind("news_content") %>'
                                    TextMode="MultiLine" Width="450px"></asp:TextBox>
                            </InsertItemTemplate>
                        </asp:TemplateField>
                        <asp:CommandField ShowEditButton="True" ShowInsertButton="True" />
                    </Fields>
                    <AlternatingRowStyle CssClass="row2" />
                </asp:DetailsView>
            </LoggedInTemplate>
            <AnonymousTemplate>
                <img src="image/shou.jpg" />请先执行<asp:LoginStatus ID="LoginStatus1" runat="server"
                    LogoutPageUrl="~/newsInsert.aspx" />
                操作&nbsp;&nbsp;
            </AnonymousTemplate>
        </asp:LoginView>
        <br />
        <br />
        <br />
        <br />
        <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionString %>"
            DeleteCommand="DELETE FROM [news] WHERE [news_id] = @news_id" InsertCommand="INSERT INTO [news] ([news_id], [news_type], [news_date], [news_subject], [news_content], [news_editor]) VALUES (@news_id, @news_type, @news_date, @news_subject, @news_content, @news_editor)"
            SelectCommand="SELECT * FROM [news]"
            UpdateCommand="UPDATE [news] SET [news_type] = @news_type, [news_date] = @news_date, [news_subject] = @news_subject, [news_content] = @news_content, [news_editor] = @news_editor WHERE [news_id] = @news_id">
            <DeleteParameters>
                <asp:Parameter Name="news_id" Type="Int32" />
            </DeleteParameters>
            <UpdateParameters>
                <asp:Parameter Name="news_type" Type="String" />
                <asp:Parameter DbType="Date" Name="news_date" />
                <asp:Parameter Name="news_subject" Type="String" />
                <asp:Parameter Name="news_content" Type="String" />
                <asp:Parameter Name="news_editor" Type="String" />
                <asp:Parameter Name="news_id" Type="Int32" />
            </UpdateParameters>
            <InsertParameters>
                <asp:Parameter Name="news_id" Type="Int32" />
                <asp:Parameter Name="news_type" Type="String" />
                <asp:Parameter DbType="Date" Name="news_date" />
                <asp:Parameter Name="news_subject" Type="String" />
                <asp:Parameter Name="news_content" Type="String" />
                <asp:Parameter Name="news_editor" Type="String" />
            </InsertParameters>
        </asp:SqlDataSource>
    
    </div>
    </form>
</body>
</html>
========================================================================================
新闻发布系统的修改、添加、删除页面。。
请大侠赐教。。按添加之后,还是出现更新的页面。。
还有更新出现SQL不支持date数据其中有错误说。。  <asp:TextBox ID="TextBox1" runat="server" Text='<%# Now() %>'></asp:TextBox>
这个Now是不是有问题。。他说上下文中不存在名称。。不过,书上是这么写的。。菜鸟求大侠指教!!

解决方案 »

  1.   

    你这个Now在哪里?cs页面中应该存在一个最少为protected的Now()函数protected string Now()
    {
     return "content that you want to be displayed!";
    }
      

  2.   

    Now函数是否存在
    很少这样写
      

  3.   

    protected string Now()
    {
     return DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
    }
      

  4.   

    在pageload里面写 
    TextBox1.text =  DateTime.Now.ToString();或者写个方法 前台调用
     public string Now()
            {
                return DateTime.Now.ToString();
            }
    //前台 <asp:TextBox ID="TextBox1" runat="server" Text=' <%= Now() %>'> </asp:TextBox>