zoukankan      html  css  js  c++  java
  • GridView的操作<1>:基本操作(编辑、更新、取消)

    GridView的基本操作:编辑      事件:RowEditing
    1protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e)
    2{
    3GridView1.EditIndex = e.NewEditIndex;
    4GridView_DataBind();//需要重新绑定
    5}
    GridView的基本操作:更新      事件:RowUpdating
     1protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
     2{
     3int click, score, times;
     4string name;
     5
     6if (REG.IsMatch(((TextBox)GridView1.Rows[e.RowIndex].Cells[3].Controls[0]).Text))
     7{
     8click = int.Parse(((TextBox)GridView1.Rows[e.RowIndex].Cells[3].Controls[0]).Text);
     9}

    10else
    11{
    12click = int.Parse(GridView1.Rows[e.RowIndex].Cells[3].Text);
    13}

    14//源代码中GridView用TemplateField实现,但是也可以适用下属方法取得单元格的值
    15//也可以用Row[e.RowIndex].FindControl("控件ID")获取控件,再进行类型转换
    16score = int.Parse(((TextBox)GridView1.Rows[e.RowIndex].Cells[2].Controls[0]).Text);
    17times = int.Parse(((TextBox)GridView1.Rows[e.RowIndex].Cells[1].Controls[0]).Text);
    18name = GridView1.Rows[e.RowIndex].Cells[0].Text;
    19//调用更新数据库的方法
    20string message = Gp.UpdatePinlun(click, times, score, name);
    21//关闭编辑模式
    22GridView1.EditIndex = -1;
    23//重新绑定数据
    24GridView_DataBind();
    25}
    GridView的基本操作:取消更新   事件:RowCancelingEdit
    1protected void GridView1_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e)
    2{
    3//关闭编辑模式
    4GridView1.EditIndex = -1;
    5//数据绑定
    6GridView_DataBind();
    7}

  • 相关阅读:
    7. 初识Python之函数
    6. 初识Python之dict和set
    5. 初识Python之循环语句
    4. 初识Python之条件语句
    3. 初识Python之列表
    原生js实现一个小小的轮波
    原生js实现弹幕
    js实现一个简单的学生管理系统
    js绘制时钟
    js实现的学生管理系统
  • 原文地址:https://www.cnblogs.com/lixx/p/1185764.html
Copyright © 2011-2022 走看看