会员
众包
新闻
博问
闪存
赞助商
HarmonyOS
Chat2DB
所有博客
当前博客
我的博客
我的园子
账号设置
会员中心
简洁模式
...
退出登录
注册
登录
代码改变世界
Cnblogs
Dashboard
Login
Home
Contact
Gallery
Subscribe
RSS
.NET技术站&&PHPER
自制力是人生的方向舵!
GridView中的rows,Cells,Controls
2008-11-11 23:16
LvSir
阅读(
1088
) 评论(
0
)
收藏
举报
GridView中的rows,Cells,Controls
rows代表第几行
Cells代表第几个表格<td></td>
Controls代表控制器
Code
1
protected
void
GridView1_RowUpdating(
object
sender, GridViewUpdateEventArgs e)
2
{
3
SqlConnection con
=
new
SqlConnection(
"
server=.;database=mr_08;uid=sa;pwd=;
"
);
4
con.Open();
5
//
获得学生编号字段
6
string
id
=
((TextBox)(GridView1.Rows[e.RowIndex].Cells[
0
].Controls[
0
])).Text.Trim();
7
//
取得文本框中输入的内容
8
string
name
=
((TextBox)(GridView1.Rows[e.RowIndex].Cells[
1
].Controls[
0
])).Text.Trim();
9
string
sex
=
((TextBox)(GridView1.Rows[e.RowIndex].Cells[
2
].Controls[
0
])).Text.Trim();
10
string
like
=
((TextBox)(GridView1.Rows[e.RowIndex].Cells[
3
].Controls[
0
])).Text.Trim();
11
string
sql
=
"
update StudentInfo set Name='
"
+
name
+
"
',sex='
"
+
sex
+
"
',[like]='
"
+
like
+
"
' where ID=
"
+
id ;
12
SqlCommand com
=
new
SqlCommand(sql, con);
13
com.ExecuteNonQuery();
14
con.Close();
15
GridView1.EditIndex
=
-
1
;
16
Bind();
17
}
为了实现梦想,无论遇到多么大的困难,都不退缩!
刷新页面
返回顶部
About