zoukankan
html css js c++ java
GridView基本的操作 编辑 更新 取消
1.html代码
<
html
xmlns
="http://www.w3.org/1999/xhtml"
>
<
head
runat
="server"
>
<
title
>
GridView基本的操作 编辑 更新 取消
</
title
>
</
head
>
<
body
>
<
form
id
="form1"
runat
="server"
>
<
div
>
<
asp:GridView
ID
="GridView1"
runat
="server"
Width
="100%"
AutoGenerateColumns
="False"
>
<
Columns
>
<
asp:BoundField
DataField
="au_id"
HeaderText
="au_id"
/>
<
asp:BoundField
DataField
="au_lname"
HeaderText
="au_lname"
/>
<
asp:BoundField
DataField
="au_fname"
HeaderText
="au_fname"
/>
<
asp:BoundField
DataField
="phone"
HeaderText
="phone"
/>
<
asp:BoundField
DataField
="address"
HeaderText
="address"
/>
<
asp:CommandField
ShowEditButton
="True"
HeaderText
="编辑"
/>
<
asp:CommandField
ShowDeleteButton
="True"
HeaderText
="删除"
/>
</
Columns
>
</
asp:GridView
>
</
div
>
</
form
>
</
body
>
</
html
>
2.cs代码
using
System;
using
System.Data;
using
System.Configuration;
using
System.Collections;
using
System.Web;
using
System.Web.Security;
using
System.Web.UI;
using
System.Web.UI.WebControls;
using
System.Web.UI.WebControls.WebParts;
using
System.Web.UI.HtmlControls;
public
partial
class
GridView_GridView_DeleteUpdate1 : System.Web.UI.Page
{
Practice.DAL.authors authorsbll
=
new
Practice.DAL.authors();
protected
void
Page_Load(
object
sender, EventArgs e)
{
if
(
!
IsPostBack)
{
DataBindGridView();
}
GridView1.RowDeleting
+=
new
GridViewDeleteEventHandler(GridView1_RowDeleting);
GridView1.RowEditing
+=
new
GridViewEditEventHandler(GridView1_RowEditing);
GridView1.RowCancelingEdit
+=
new
GridViewCancelEditEventHandler(GridView1_RowCancelingEdit);
GridView1.RowUpdating
+=
new
GridViewUpdateEventHandler(GridView1_RowUpdating);
}
void
GridView1_RowDeleting(
object
sender, GridViewDeleteEventArgs e)
{
string
id
=
GridView1.Rows[e.RowIndex].Cells[
0
].Text.Trim();
authorsbll.Delete(id);
//
删除,函数自己写
DataBindGridView();
//
重新绑定数据源
}
void
GridView1_RowEditing(
object
sender, GridViewEditEventArgs e)
{
GridView1.EditIndex
=
e.NewEditIndex;
DataBindGridView();
}
void
GridView1_RowCancelingEdit(
object
sender, GridViewCancelEditEventArgs e)
{
GridView1.EditIndex
=
-
1
;
DataBindGridView();
}
void
GridView1_RowUpdating(
object
sender, GridViewUpdateEventArgs e)
{
string
aa
=
(((TextBox)(GridView1.Rows[e.RowIndex].Cells[
0
].Controls[
0
])).Text.ToString().Trim());
GridView1.EditIndex
=
-
1
;
DataBindGridView();
}
private
void
DataBindGridView()
{
DataSet ds
=
authorsbll.GetList(
""
);
GridView1.DataSource
=
ds;
GridView1.DataBind();
}
}
查看全文
相关阅读:
yCharm代码格式化(自动加空格)
python调用另一个.py中的类或函数
深度学习04--卷积神经网络
深度学习03--神经网络
深度学习02--数据读取
深度学习01--TensorFlow
机器学习08--实战案例
机器学习07--无监督学习-K-means算法
机器学习06--逻辑回归
机器学习05--线性回归+岭回归
原文地址:https://www.cnblogs.com/lds85930/p/1294828.html
最新文章
JS
正则表达式
数组从大到小或从小到大排列
pop和push等使用方法,every和some、join
数组
Javascript中变量作用域(2)
Javascript中this关键字
Javascript中变量作用域
Javascript中Array(数组)对象常用的几个方法
创建一个JS函数,运用JS中arguments对象
热门文章
MVC 用法小语法摘录
使用ajax传递及接收数据
C# windows窗体程序打包安装及卸载
winform 绘制label 中文字
KeyPress事件
strip()方法
Python replace()方法
Python startswith() 方法
匿名函数
python字符串之format格式化函数
Copyright © 2011-2022 走看看