GridView的操作:基本操作(編輯、更新、取消)

來源:互聯網
上載者:User
GridView的基本操作:編輯      事件:RowEditing1protected 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的基本操作:取消更新   事件:RowCancelingEdit1protected void GridView1_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e)
2{
3//關閉編輯模式
4GridView1.EditIndex = -1;
5//資料繫結
6GridView_DataBind();
7}

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.