GridVie中通过RowCommand 进行 编辑 保存 删除操作

aspx页面

        <Columns>

            <asp:BoundField HeaderText="机型" DataField="phoneTypeName" ReadOnly="true" />
       
            <asp:BoundField HeaderText="壳件编码" DataField="attachmentCode" ReadOnly="true" />
            <asp:TemplateField HeaderText="壳件名称">
                <ItemTemplate>
                    <%#Eval("attachmentName")%>
                </ItemTemplate>
<%--                <EditItemTemplate>
                    <asp:TextBox ID="txtEditName" runat="server" Text='<%#Eval("attachmentName") %>'>'></asp:TextBox>
                </EditItemTemplate>--%>
            </asp:TemplateField>
            <asp:TemplateField HeaderText="数量">
                <ItemTemplate>
                <asp:Label ID="lblEditRemark" runat="server" Text='<%#Eval("aCount") %>'>></asp:Label>
                </ItemTemplate>
                <EditItemTemplate>
                    <asp:TextBox ID="txtEditRemark" runat="server" Text='<%#Eval("aCount") %>'>'></asp:TextBox>
                </EditItemTemplate>
            </asp:TemplateField>
            <asp:BoundField HeaderText="操作人" DataField="operator" ReadOnly="true" />
            <asp:BoundField HeaderText="操作时间" DataField="operateTime" ReadOnly="true" />
             <asp:TemplateField HeaderText="操作">
                <ItemTemplate>
                    <asp:LinkButton ID="lbEdit" runat="server" CommandName="Edit" 
                    CommandArgument='<%# ((GridViewRow) Container).RowIndex+"&"+ Eval("Id")+"&"+Eval("BomId") %>' >编辑</asp:LinkButton>
                    <asp:LinkButton ID="lbDel" runat="server" CommandName="Delete" 
                        CommandArgument='<%# ((GridViewRow) Container).RowIndex+"&"+ Eval("Id")+"&"+Eval("BomId") %>'  
                        OnClientClick="return window.confirm('确定要删除吗?')">删除</asp:LinkButton>

                </ItemTemplate>
                <EditItemTemplate>
                    <asp:LinkButton ID="lbSave" runat="server" CommandName="Update" ValidationGroup="editMobile"
                    CommandArgument='<%# ((GridViewRow) Container).RowIndex+"&"+ Eval("Id")+"&"+Eval("BomId") %>' >保存</asp:LinkButton>

                    <asp:LinkButton ID="lbCancel" runat="server" CommandName="Cancel">取消</asp:LinkButton>
                </EditItemTemplate>
            </asp:TemplateField>
        </Columns>


aspx.cs

       /// <summary>
        /// GridView编辑 保存 删除操作
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void gvResult_RowCommand(object sender, GridViewCommandEventArgs e)
        {


            if (e.CommandName == "Edit" || e.CommandName == "Update" || e.CommandName == "Delete")
            {


                string[] arg = e.CommandArgument.ToString().Split('&');
                int index = Convert.ToInt32(arg[0]);
                int id = Convert.ToInt32(arg[1]);
                int bomId = Convert.ToInt32(arg[2]);
                switch (e.CommandName)
                {
                    case "Edit":
                        if (!bll.ExistsBomFlowChart(bomId))
                        {
                            gvResult.EditIndex = index;
                            Bind();
                        }
                        else
                        {
                            Page.ClientScript.RegisterStartupScript(this.GetType(), "", "alert('Bom信息不能编辑!');", true);
                        }


                        break;
                    case "Update":
                        GridViewRow row = gvResult.Rows[index];
                        TextBox txtEditRemark = row.FindControl("txtEditRemark") as TextBox;


                        gvResult.EditIndex = -1;
                        Bind();
                        break;
                    case "Delete":
                        if (bll.ExistsBomFlowChart(bomId))
                        {
                            Page.ClientScript.RegisterStartupScript(this.GetType(), "", "alert('Bom信息不能删除!');", true);
                        }
                        else
                        {
                            GridViewRow rowDel = gvResult.Rows[index];
                            Label lblEditRemark = rowDel.FindControl("lblEditRemark") as Label;

                        Bind();
                        break;
                }
            }
        }


        /// <summary>
        /// 取消编辑
        /// </summary>
        protected void gvResult_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e)
        {
            gvResult.EditIndex = -1;
            Bind();
        }


        //编辑
        protected void gvResult_RowEditing(object sender, GridViewEditEventArgs e)
        {


        }
        //保存
        protected void gvResult_RowUpdating(object sender, GridViewUpdateEventArgs e)
        {


        }
        //删除
        protected void gvResult_RowDeleting(object sender, GridViewDeleteEventArgs e)
        {


        }

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 3
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值