前台代码如下:
<asp:DetailsView ID="dvGroupInfo" runat="server" AutoGenerateRows="False"                 
                AutoGenerateInsertButton="True" 
                AutoGenerateEditButton="True"
                DataKeyNames="AccountId" HeaderText="Group details"
                Height="50px" Width="125px" Font-Size="8.25pt"                 
                DefaultMode="Edit" onitemcommand="dvGroupInfo_ItemCommand" 
                oniteminserted="dvGroupInfo_ItemInserted" 
                oniteminserting="dvGroupInfo_ItemInserting" 
                onmodechanging="dvGroupInfo_ModeChanging" 
        onpageindexchanging="dvGroupInfo_PageIndexChanging">
                <Fields>                   
                    <asp:BoundField DataField="AccountId" HeaderText="AccountId" 
                        SortExpression="AccountId" Visible="true"/>
                    <asp:TemplateField HeaderText="AccountName">
                        <EditItemTemplate>
                            <asp:TextBox ID="txtAccountName" runat="server" 
                                Text='<%# Bind("AccountName") %>'></asp:TextBox>                            
                        </EditItemTemplate>
                        <InsertItemTemplate>
                            <asp:TextBox ID="txtAccountName" runat="server" 
                                Text='<%# Bind("AccountName") %>'></asp:TextBox>                            
                        </InsertItemTemplate>
                        <ItemTemplate>
                            <asp:Label ID="lblAccountName" runat="server" Text='<%# Bind("AccountName") %>'></asp:Label>
                        </ItemTemplate>
                    </asp:TemplateField>
                </Fields>
            </asp:DetailsView>====================
后台代码:
Button1.Text = e.CommandName;
        if (e.CommandName == "Cancel")
        {
            dvGroupInfo.ChangeMode(DetailsViewMode.ReadOnly);
            pnlGroupInfo.Visible = false;
        }
=============
设置了断点,只有cancel的commandname能进来======================
然后看了页面源代码:如下:
<tr>
<td colspan="2"><a href="javascript:__doPostBack('dvGroupInfo$ctl02','')">更新</a>&nbsp;<a href="javascript:__doPostBack('dvGroupInfo','Cancel$0')">取消</a></td>
</tr>

解决方案 »

  1.   

    更新 没有指定 CommandName 属性
      

  2.   

    cancel 为啥不用指定?
    如果要指定,如何给textbox或albel指定?
      

  3.   

    只能在按钮制定命令,textbox或label不能。
      

  4.   

    只能在按钮制定命令,textbox或label不能。
    ==================
    没按钮咋办?只有detailsview的默认按钮哈
      

  5.   

    asp.net下detailsview中Item_Command事件只能响应cancel的commandname
    ------------------
    update这些也是响应的,其它的你要自己写commandname
      

  6.   

    最近做东西也在用detailsview 问题也相当多 继续学习中