<asp:DataList ID="DataList1" runat="server" BackColor="White" BorderColor="#E7E7FF" BorderStyle="None" BorderWidth="1px" CellPadding="3" GridLines="Horizontal" OnEditCommand="DataList1_EditCommand"  OnUpdateCommand="DataList1_UpdateCommand" OnCancelCommand="DataList1_CancelCommand">
        
            <FooterStyle BackColor="#B5C7DE" ForeColor="#4A3C8C" />
            <AlternatingItemStyle BackColor="#F7F7F7" />
            <ItemStyle BackColor="#E7E7FF" ForeColor="#4A3C8C" />
            <SelectedItemStyle BackColor="#738A9C" Font-Bold="True" ForeColor="#F7F7F7" />
            <HeaderStyle BackColor="#4A3C8C" Font-Bold="True" ForeColor="#F7F7F7" />
            <HeaderTemplate><center><h>电脑图书序号</h></center></HeaderTemplate>
            <ItemTemplate >
                <asp:LinkButton ID="LinkButton1" Text ="详细" CommandName ="Edit" runat="server"></asp:LinkButton>
                <%# DataBinder.Eval (Container.DataItem ,"name") %>
            </ItemTemplate>
            <EditItemTemplate >
                电脑图书:序号
                <asp:Label ID="LblNum" runat="server" Text=<%# DataBinder.Eval (Container.DataItem ,"num") %>></asp:Label><br />
                电脑图书名:
                <asp:TextBox ID="computerBook" runat="server" Text=<%#DataBinder.Eval (Container.DataItem ,"name") %>></asp:TextBox><br />
                价格:
                <asp:TextBox ID="Txtprice" runat="server" Text ='<%#DataBinder.Eval(Container.DataItem,"price") %>'></asp:TextBox><br />
                <center >
                    <asp:Button ID="Button1" runat="server" Text="修改" CommandName ="update" />
                    <asp:Button ID="Button2" runat="server" Text="撤消" CommandName ="cancel" />
                </center>
            </EditItemTemplate>
        </asp:DataList>
上面红色的地方为什么CommandName不能修改了。是不是固定的。比如不能改成CommandName ="updata",改成这样都不行。

解决方案 »

  1.   

    如果楼主是想直接使用dl当中的updateCommand,cancelCommand事件,就必须使用那种方式,不能更改.
    另外也可以通过itemCommand事件,按自定CommandName进行处理
    eg
    protected void dList_ItemCommand(object source, DataListCommandEventArgs e)
        {
            if (e.CommandName == "e")
            {
                dList.EditItemIndex = e.Item.ItemIndex;
                mfbind();
            }
            if (e.CommandName == "u")
            {
                dList.EditItemIndex = -1;
                mfbind();
            }
       }