gridview checkbox应用 C# 小问题

来源:百度知道 编辑:UC知道 时间:2024/06/28 16:19:34
做一个投票的界面 用gridview读数据库 checkbox嵌套在里面 怎么样点buttonClick事件 让他更新数据库 比如字段 number会自动加1

foreach (GridViewRow rowview in GridView1.Rows)
{

CheckBox check = (CheckBox)rowview.Cells[0].FindControl("CheckBox1");

if (check.Checked)
{
string strconn = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source = " + System.Web.HttpContext.Current.Server.MapPath("fuyou.mdb");
OleDbConnection conn = new OleDbConnection(strconn);
conn.Open();
string updategong = "update vote set vote_num= vote_num + 1 where .................................
OleDbCommand updatecmd = new OleDbCommand(updategong, conn);
updatecmd.ExecuteNonQuery();

数据库更新语句该怎么写 想获取选中的checkbox后面的字段内容 再让他更新表里的票数

//GridView1.DataKeys[rowview].Value取GridView1绑定的主键
int nid = Convert.ToInt32(GridView1.DataKeys[rowview].Value);
//id是我假设的字段主键
string updategong = "update vote set vote_num= vote_num + 1 where id="+nid;
这样就可以了啊;