只有ItemCommand可以捕捉到命令名称,其他几个事件都捕捉不到命令名称,不知何故ASP.NET 2.0<asp:DataList ID="DataList1" runat="server" Width="100%" DataKeyField="LeavewordsID"
                        OnItemCommand="DataList1_ItemCommand"  CellPadding="3" ForeColor="#333333" GridLines="Both" OnEditCommand="DataList1_EditCommand"  BorderWidth="1px" ShowFooter="False" OnCancelCommand="DataList1_CancelCommand" OnSelectedIndexChanged="DataList1_SelectedIndexChanged" OnUpdateCommand="DataList1_UpdateCommand">
                        <ItemTemplate>
                            <table width="100%" border="0" cellspacing="0" cellpadding="5">
                                <tr>
                                    <td width="100" align="center" valign="top" class="dian">
                                        <b><a href="<%#DataBinder.Eval(Container.DataItem, "link")%>" target="_blank">
                                            <%#DataBinder.Eval(Container.DataItem, "NickName")%>
                                        </a></b>
                                    </td>
                                    <td width="150" align="center" valign="top" class="dian">
                                        <%#DataBinder.Eval(Container.DataItem, "QuestionTime")%>
                                    </td>
                                    <td class="dian">
                                        <%#DataBinder.Eval(Container.DataItem, "Question")%></td>
                                    <td width="50" rowspan="2" align="center">
                                        <asp:LinkButton CommandArgument="" CommandName="Del" ID="Del" runat="server" Text="&lt;span onclick=&quot;return confirm('确认删除当前数据吗?')&quot;&gt;删除&lt;/span&gt;"></asp:LinkButton></td>
                                </tr>
                                <tr>
                                    <td align="center">
                                        <asp:LinkButton CommandName="Reply" runat="server" ID="Linkbutton1" Text='<%#DataBinder.Eval(Container.DataItem, "reply")%>'></asp:LinkButton></td>
                                    <td align="center">
                                       <font color="#888888"> <%#DataBinder.Eval(Container.DataItem, "AnswerTime")%></font>
                                    </td>
                                    <td>
                                        <%#DataBinder.Eval(Container.DataItem, "Answer")%></td>
                                </tr>
                            </table>
                        </ItemTemplate>
                        <HeaderTemplate>
                            <table width="100%" border="0" cellspacing="0" cellpadding="5">
                                <tr>
                                    <td width="100"  valign="top" align="center">
                                        <font color="#FFFFFF"><b>留言人</b></font></td>
                                    <td width="150" valign="top" align="center">
                                        <font color="#FFFFFF"><strong>留言/回复时间</strong></font></td>
                                    <td align="center">
                                        <font color="#FFFFFF"><strong>留言/回复内容</strong></font></td>
                                    <td width="50" align="center">
                                        <font color="#FFFFFF"><strong>删除</strong></font></td>
                                </tr>
                            </table>
                        </HeaderTemplate>
                        <EditItemTemplate>
                             <table width="100%" border="0" cellspacing="0" cellpadding="5">
                                <tr>
                                    <td width="100" align="center" class="dian">
                                        <b><a href="<%#DataBinder.Eval(Container.DataItem, "link")%>" target="_blank">
                                            <%#DataBinder.Eval(Container.DataItem, "NickName")%>
                                        </a></b>                                    </td>
                                    <td width="150" align="center" class="dian">
                                        <%#DataBinder.Eval(Container.DataItem, "QuestionTime")%>                                    </td>
                                    <td class="dian"><%#DataBinder.Eval(Container.DataItem, "Question")%></td>
                                </tr>
                                <tr>
                                    <td colspan="2" align="right">输入回复内容:                                  </td>
                                    <td>
                                       <asp:TextBox runat="server" TextMode="MultiLine" Columns="58" Rows="8" ID="TAnswer">                                      </asp:TextBox><br />
                                        <asp:Button ID="ReplyMessage" runat="server" Text="确认" CommandName="ReplyMessage"
                                                        CausesValidation="true"></asp:Button>
                                                    <asp:Button ID="Cancel" runat="server" Text="取消" CommandName="Cancel" CausesValidation="false">                                                    </asp:Button></td>
                                </tr>
                            </table>
                                        
                        </EditItemTemplate>
                        <FooterStyle BackColor="#990000" Font-Bold="True" ForeColor="White" />
                        <SelectedItemStyle BackColor="#FFCC66" Font-Bold="True" ForeColor="Navy" />
                        <AlternatingItemStyle BackColor="White" />
                        <ItemStyle BackColor="#FFFBD6" ForeColor="#333333" />
                        <HeaderStyle BackColor="DarkOrange" Font-Bold="True" ForeColor="White" />
                    </asp:DataList>

解决方案 »

  1.   

    看看你名称是什么是不是update,cancel,delete
     另外看看事件有没有丢失
      

  2.   

    在datalist中内置了几个commandname分别是
    编辑 edit
    删除 delete
    更新 update
    取消 cancel
      

  3.   

    同意truelove12(这些年来,我走了很多弯路!) 所说.
      

  4.   

    名称换成这几个都没有用!取消和更新命令没有起到作用!编辑是用ItemCommand
      

  5.   

    其实不用看DataList里面什么劳什子的commandname了,直接用button触发点击事件即可
    如果你要删除前确认的话,就在Page_Load里面加
    btnDeleteType.Attributes.Add("onClick","return confirm('你确定要删除所选记录?')");
    就可以了
    btnDeleteType是你按钮控件的名称