现在的位置: 首页 > 综合 > 正文

DataList编辑功能

2013年11月19日 ⁄ 综合 ⁄ 共 4126字 ⁄ 字号 评论关闭

 我现在正在做一个新闻发布系统,而我的代码如下:

<%@ Page Language="C#" AutoEventWireup="true" ValidateRequest="false" CodeFile="NewsDetails.aspx.cs" Inherits="Admin_NewsDetails" %>

<%@ Register assembly="FreeTextBox" namespace="FreeTextBoxControls" tagprefix="FTB" %>

<!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>
    <style type="text/css">
        .style1
        {
            width: 129px;
        }
    </style>
</head>
<body>
    <form id="form1" runat="server">
    <div>
    <asp:DataList ID="dlNewsInfo" runat="server" style="margin-right: 259px"
            Width="80%" oncancelcommand="dlNewsInfo_CancelCommand"
            oneditcommand="dlNewsInfo_EditCommand" onitemcommand="dlNewsInfo_ItemCommand"
            onupdatecommand="dlNewsInfo_UpdateCommand" Height="1532px">
            <ItemTemplate>
                <table width="100%"  border="1">
                <tr>
    <td class="style1">新闻所属类别:</td>
    <td>
        <asp:TextBox ID="txtSSortInfo" runat="server" Text='<%# Eval("SecondSort.SecondSort1") %>'></asp:TextBox>&nbsp;&nbsp;<asp:DropDownList ID="ddlNewsSort" runat="server">
        </asp:DropDownList>
    </td>
  </tr>
  <tr>
    <td class="style1">标题:</td>
    <td>
        <asp:TextBox ID="txtNewsTitel" runat="server" Height="23px" Width="424px" Text='<%# Eval("NewsTitle") %>'></asp:TextBox></td>
  </tr>
  <tr>
    <td class="style1">来源:</td>
    <td>
        <asp:TextBox ID="txtNewsSource" runat="server" Text='<%# Eval("NewsSource") %>'></asp:TextBox></td>
  </tr>
  <tr>
    <td class="style1">发布时间:</td>
    <td>
     <asp:TextBox ID="txtNewsTime" runat="server" Text='<%# Eval("NewsTime") %>'></asp:TextBox>
        
  </tr>
  <tr>
    <td class="style1">内容:</td>
    <td><FTB:FreeTextBox ID="ftbNewsContents" ButtonPath="../images/officeXP/" runat="server" Text='<%# Eval("NewsContent") %>'>
                            </FTB:FreeTextBox></td>
       </td>
  </tr>
  <tr>
    <td class="style1">审核是否通过:</td>
    <td>
    <asp:RadioButton ID="rdoNoExamine" Checked="true" runat="server" Text="未审核"/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
        <asp:RadioButton ID="rdoExamineS" runat="server" Text="审核通过"/>
        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
        <asp:RadioButton ID="rdoEaxmineF" runat="server" Text="审核失败" />
    </td>
  </tr>
   <tr>
    <td class="style1">优先级设置:</td>
    <td>
    <asp:RadioButton ID="rdoShowIndex" runat="server" Text="显示在首页"/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
        <asp:RadioButton ID="rdoFirstRow" runat="server" Text="显示第一行"/>
    </td>
  </tr>
  <tr>
    <td class="style1">备注:</td>
    <td>
        <asp:TextBox ID="txtRemark" runat="server" Height="64px" TextMode="MultiLine"
            Width="378px" Text='<%# Eval("Remark") %>'></asp:TextBox></td>
  </tr>
  <tr>
    <td height="28" class="style1">&nbsp;</td>
    <td>
        <asp:Button ID="btnPublished" runat="server" Text="确定发布到前台"
            onclick="btnPublished_Click" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
        <asp:Button ID="btnFail" runat="server" Text="审核未通过" onclick="btnFail_Click" />
        </td>
  </tr>
</table>
</ItemTemplate>
        </asp:DataList>

    </div>
    </form>
</body>
</html>

 

后台代码是:

    /// <summary>
    /// 更新
    /// </summary>
    /// <param name="source"></param>
    /// <param name="e"></param>
    protected void dlNewsInfo_UpdateCommand(object source, DataListCommandEventArgs e)
    {
        string ssort = ((TextBox)e.Item.FindControl("txtSSortInfo")).ToString();
        string newsTitle = ((TextBox)e.Item.FindControl("txtNewsTitel")).ToString();
        string newsSource = ((TextBox)e.Item.FindControl("txtNewsSource")).ToString();
        string newsTime = ((TextBox)e.Item.FindControl("txtNewsTime")).ToString();
        string newsContent = ((FreeTextBox)e.Item.FindControl("ftbNewsContents")).ToString();
        string newsRemark = ((TextBox)e.Item.FindControl("txtRemark")).ToString();

        News news = new News();
        news.SecondSort.SecondSort1 = ssort;
        news.NewsTitle = newsTitle;
        news.NewsSource = newsSource;
        news.NewsContent = newsContent;
        news.Remark = newsRemark;

        if (news != null)
        {
            NewsManage.ModifyNews(news);
  
            ScriptManager.RegisterClientScriptBlock(dlNewsInfo, this.GetType(), "click", "alert(新闻审批通过!)", true);

        }
    }

 

我在调试的过程中,总是不能进入dlNewsInfo_UpdateCommand这个方法!

 

有那个高手能救我啊?

抱歉!评论已关闭.