关于 GridView1的编辑状态和非编辑状态取值 GridViewEditEventArgs e ,GridViewCancelEditEventArgs e

//=----------------------------------------------------------------------非编辑状态

protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e)
        {
            //string id = ( ( Label )GridView1.Rows[e.RowIndex].FindControl( "Label1" ) ).Text;
            string FoodTemp = ( ( Label )GridView1.Rows[e.NewEditIndex].FindControl( "Label1" ) ).Text;

//这里就获取到了当前行中 Label1的数据了NewEditIndex
            //Response.Write( "<script type='text/javascript'>alert('" + FoodTemp + "')</script>" );
            GridView1.EditIndex = e.NewEditIndex;
            BindGridView();
        }

 

 

//-----------------------------------------------------------------------------编辑状态

 protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
        {
                string id = ( ( Label )GridView1.Rows[e.RowIndex].FindControl( "IdLabel" ) ).Text;

//这里就是获取到了当前行中ID Label的数据了e.RowIndex
                //string id = ( ( TextBox )this.GridView1.Rows[e.RowIndex].Cells[0].Controls[0] ).Text.ToString();
                // Response.Write( "<script type='text/javascript'>alert('"+id+"')</script>" );
                DB db = new DB();
                DataTable dt = new DataTable();
                string Ntext = ( ( TextBox )this.GridView1.Rows[e.RowIndex].Cells[1].Controls[0] ).Text.ToString();

//这里则是获取到了当前行中第2列的值e.RowIndex
                string Ctext = ( ( TextBox )this.GridView1.Rows[e.RowIndex].Cells[2].Controls[0] ).Text.ToString();
                string BFtext = ( ( DropDownList )GridView1.Rows[e.RowIndex].FindControl( "DropDownList1" ) ).Text;
                 //Response.Write( "<script type='text/javascript'>alert('" + BFtext + "')</script>" );
                dt = db.GetTable( "UPDATE testtable SET name ='" + Ntext + "',city='" + Ctext + "',bestfood='" + BFtext + "' WHERE id=" + id );
                GridView1.EditIndex = -1;
                BindGridView();
           }           

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值