• gridview 的添加删除等技巧 全部按名称取值


    情况1:

    使用dataSource绑定的时候使用一个页面变量,GridViewFlow_RowDeleting先执行,紧接着SqlDataSourceFlow_Deleting

    private int rowIndex;
        protected void GridViewFlow_RowDeleting(object sender, GridViewDeleteEventArgs e)
        {
            rowIndex = e.RowIndex;
        }
        protected void SqlDataSourceFlow_Deleting(object sender, SqlDataSourceCommandEventArgs e)
        {
            e.Command.Parameters["v_spfabh"].Value = GridViewFlow.DataKeys[rowIndex]["spfabh"].ToString();
            e.Command.Parameters["v_qztz"].Value = GridViewFlow.DataKeys[rowIndex]["qztz"].ToString();
            e.Command.Parameters["v_hztz"].Value = GridViewFlow.DataKeys[rowIndex]["hztz"].ToString();
            e.Command.Parameters["v_gwbh"].Value = GridViewFlow.DataKeys[rowIndex]["gwbh"].ToString();
            e.Command.Parameters["v_gzlx"].Value = GridViewFlow.DataKeys[rowIndex]["gzlx"].ToString();
            e.Command.Parameters["v_czr"].Value = sysUser.Name;
        }

    情况2:使用tableAdapter

    protected void GridViewApproval_RowDeleting(object sender, GridViewDeleteEventArgs e)
        {
            try
            {
                DataSetClass.ApprovalStateDataTable dt = new DataSetClass.ApprovalStateDataTable();
                DataSetClassTableAdapters.ApprovalStateTableAdapter ta = new DataSetClassTableAdapters.ApprovalStateTableAdapter();
                ta.P_DELCONTRACTSTATE(GridViewApproval.DataKeys[e.RowIndex]["HTZTZ"].ToString(), sysUser.Name);
                this.ShowStateList();
            }
            catch (Exception ex)
            {
                WebAction.MessageBox(this, "add", ex.Message, null);
            }
        }

    需要注意的:如果没使用datasource进行页面的绑定的话,删除或其他操作后,需要主动进行DataBind()的操作,以便删除后能够刷新显示为删除后的列表数据。

  • 相关阅读:
    《算法竞赛进阶指南》0x12 队列 POJ2259 Team Queue
    《算法竞赛进阶指南》0x11栈 单调栈求矩形面积 POJ2559
    《算法竞赛进阶指南》0x11 栈 求解中缀表达式
    19.职责链模式(Chain of Responsibility Pattern)
    16.观察者模式(Observer Pattern)
    17.解释器模式(Interpreter Pattern)
    15. 迭代器模式(Iterator Pattern)
    14.命令模式(Command Pattern)
    12.代理模式(Proxy Pattern)
    13.模板方法(Template Method)
  • 原文地址:https://www.cnblogs.com/keyrratuff/p/1633526.html
Copyright © 2020-2023  润新知