C# GridView使用 与 DataList分页。

本文介绍了如何在ASP.NET中实现GridView控件的编辑与更新功能。通过添加编辑、更新、取消列并设置相应的事件处理程序,在用户界面上实现了数据的交互式编辑。详细解释了RowEditing和RowUpdating事件的处理逻辑。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

3. 使用"编辑" 功能
          1  先添加一列 "编辑、更新、取消"
          2  GridView 属性的 事件里 有RowEditing 双击进入后台:

  protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e)
    {
        int index = e.NewEditIndex;
        this.GridView1.EditIndex = index;
       //这样写是错误的: this.GridView1.DataBind();
        this.InitGridView();
    }

4 . 使用更新 UpDating

    protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
    {
        int id = -1;
        string ot_name = string.Empty;
        string way = string.Empty;
        string fenlei = string.Empty;

        try
        {
            id = Convert.ToInt32(this.GridView1.DataKeys[e.RowIndex].Value);
        }
        catch
        {
 
        }
        TextBox tb = (TextBox)(this.GridView1.Rows[e.RowIndex].Cells[1].Controls[0]);
        TextBox tb1 = (TextBox)(this.GridView1.Rows[e.RowIndex].Cells[2].Controls[0]);
        TextBox tb2 = (TextBox)(this.GridView1.Rows[e.RowIndex].Cells[3].Controls[0]);
        if (tb != null)
        {
            ot_name = tb.Text;
        }
        if (tb1 != null)
        {
            way = tb1.Text;
        }
        if (tb2 != null)
        {
            fenlei = tb2.Text;
        }
        bool bo = false;
        bo = new ChuLi.Class1().Updating(ot_name, way, fenlei,id);
        if (bo == true)
        {
            this.RegisterStartupScript("sss", "<script>alert('修改成功')</script>");
        }
        else
        {
            this.RegisterStartupScript("sss", "<script>alert('修改失败')</script>");
     

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值