<itemtemplate>
<TR >
<td width="40">
<asp:Button id="btnModify" runat="server" CommandName="edit" Text="编辑" EnableViewState="true"></asp:Button></td>
<td width="40">
<asp:Button id="delete" runat="server" CommandName="delete" Text="删除" CommandArgument='<%# DataBinder.Eval(Container.DataItem, "APTITUDE_SEQ") %>'> </asp:Button>
</td>
<TD><%# DataBinder.Eval(Container.DataItem, "APTITUDE_LEVEL") %></TD>
<TD><%# DataBinder.Eval(Container.DataItem, "APTITUDE_NUM") %>&nbsp;</TD>
<TD><%# DataBinder.Eval(Container.DataItem, "PASS_DEPT") %>&nbsp;</TD>
<TD><%# DataBinder.Eval(Container.DataItem, "PASS_DATE","{0:d}") %>&nbsp;</TD>
<TD><%# DataBinder.Eval(Container.DataItem, "EFFECT_STARTDATE","{0:d}") %>&nbsp;</TD>
<TD><%# DataBinder.Eval(Container.DataItem, "EFFECT_ENDDATE","{0:d}") %>&nbsp;</TD>
<TD><%# DataBinder.Eval(Container.DataItem, "REMARK") %>&nbsp;</TD>
</TR>
</itemtemplate>cs文件中关联事件处理
this.DataList1.DeleteCommand += new System.Web.UI.WebControls.DataListCommandEventHandler(this.DataList1_DeleteCommand);

发现了一个很不爽的问题,直接使用button没法执行DataList1_DeleteCommand函数
但是将button换成linkbutton就可以执行DataList1_DeleteCommand函数。
这到底是为什么啊!太痛苦了。

解决方案 »

  1.   

    LinkButton有没有加上CommandName="delete"这个属性呀。
      

  2.   

    不会吧,DataList的EnableViewState="true"试试。
      

  3.   

    晕了,不是阿
    都是一样啊,没有少加任何属性
    是:
    LinkButton 能实现函数的正常执行
    Button 不能实现函数的正常执行
      

  4.   

    CommandName="delete"
    请注意上述参数的写法,应是Delete,而不是delete,注意大小写
    button不可能不能执行的,有问题应该是你自己的问题.
    如果确实查不出来,你可尝试新建立一个页面,简化代码,尝试一下看看.
      

  5.   

    确实还是不行,为此专门弄了个演示程序<%@ Page language="c#" Codebehind="WebForm3.aspx.cs" AutoEventWireup="false" Inherits="WebApplication2.WebForm3" %>
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
    <HTML>
    <HEAD>
    <title>WebForm3</title>
    <meta name="GENERATOR" Content="Microsoft Visual Studio .NET 7.1">
    <meta name="CODE_LANGUAGE" Content="C#">
    <meta name="vs_defaultClientScript" content="JavaScript">
    <meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5">
    </HEAD>
    <body MS_POSITIONING="GridLayout">
    <form id="Form1" method="post" runat="server">
    <asp:DataList id="DataList1" style="Z-INDEX: 101; LEFT: 24px; POSITION: absolute; TOP: 72px" runat="server"
    BorderColor="#CC9966" BorderStyle="None" BackColor="White" CellPadding="4" GridLines="Both"
    BorderWidth="1px" Height="254px">
    <SelectedItemStyle Font-Bold="True" ForeColor="#663399" BackColor="#FFCC66"></SelectedItemStyle>
    <SelectedItemTemplate>
    <FONT face="宋体"></FONT>
    </SelectedItemTemplate>
    <ItemStyle ForeColor="#330099" BackColor="White"></ItemStyle>
    <ItemTemplate>
    <TABLE id="Table1" cellSpacing="1" cellPadding="1" width="300" border="1">
    <TR bgColor="#ffffff">
    <td width="40">
    <asp:Button id="Edit" runat="server" CommandName="Edit" Text="编辑" CommandArgument='<%# DataBinder.Eval(Container.DataItem, "APTITUDE_SEQ") %>'>
    </asp:Button></td>
    <td width="40">
    <asp:LinkButton id="Delete" BorderColor="#6600ff" runat="server" CommandName="Delete" Text="删除" CommandArgument='<%# DataBinder.Eval(Container.DataItem, "APTITUDE_SEQ") %>'>
    </asp:LinkButton>
    </td>
    </TR>
    </TABLE>
    </FONT>
    </ItemTemplate>
    <FooterStyle ForeColor="#330099" BackColor="#FFFFCC"></FooterStyle>
    <HeaderStyle Font-Bold="True" ForeColor="#FFFFCC" BackColor="#990000"></HeaderStyle>
    </asp:DataList>
    <asp:Label id="Label1" style="Z-INDEX: 102; LEFT: 24px; POSITION: absolute; TOP: 32px" runat="server"
    Width="296px">Label</asp:Label>
    </form>
    </body>
    </HTML>
    cs文件public class WebForm3 : System.Web.UI.Page
    {
    protected System.Web.UI.WebControls.Label Label1;
    protected System.Web.UI.WebControls.DataList DataList1;

    private void Page_Load(object sender, System.EventArgs e)
    {
    DataList1.DataSource = Getdata();
    DataList1.DataBind();
    } #region Web 窗体设计器生成的代码
    override protected void OnInit(EventArgs e)
    {
    //
    // CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
    //
    InitializeComponent();
    base.OnInit(e);
    }

    /// <summary>
    /// 设计器支持所需的方法 - 不要使用代码编辑器修改
    /// 此方法的内容。
    /// </summary>
    private void InitializeComponent()
    {    
    this.DataList1.EditCommand += new System.Web.UI.WebControls.DataListCommandEventHandler(this.DataList1_EditCommand);
    this.DataList1.DeleteCommand += new System.Web.UI.WebControls.DataListCommandEventHandler(this.DataList1_DeleteCommand);
    this.Load += new System.EventHandler(this.Page_Load); }
    #endregion private void DataList1_DeleteCommand(object source, System.Web.UI.WebControls.DataListCommandEventArgs e)
    {
    Label1.Text = "DataList1_DeleteCommand" + e.CommandArgument.ToString();
    } private DataTable Getdata()
    {
    DataTable table1 = new DataTable();
    table1.Columns.Add(new DataColumn("APTITUDE_SEQ",System.Type.GetType("System.String")));
    //
    for(int i = 0;i < 10;i++)
    {
    DataRow row = table1.NewRow();
    row["APTITUDE_SEQ"] = i.ToString(); table1.Rows.Add(row);
    } return table1;
    } private void DataList1_EditCommand(object source, System.Web.UI.WebControls.DataListCommandEventArgs e)
    {
    Label1.Text = "DataList1_EditCommand" + e.CommandArgument.ToString();
    }
    }发现还是不行
    LinkButton能正常执行到
    但是Button的那个函数不能执行到
    快疯了,是不是我的开发环境有问题啊
      

  6.   

    问题在哪里?
    在你的page_load里面的写法有问题.你应该如下:private void Page_Load(object sender, System.EventArgs e)
    {
    if(!this.IsPostBack)
    {
    DataList1.DataSource = Getdata();
    DataList1.DataBind();
    }
    }