public list()
{
InitializeComponent(); DataSet ds = dataconn.getlist("select top " + pagesize + " content,zz from thread t,user u where u.zzid=t.zzid order by id desc");
this.dataGridView1.DataSource = ds.Tables[0].DefaultView;
this.dataGridView1.Columns[0].HeaderText = "内容";
this.dataGridView1.Columns[1].HeaderText = "作者"; DataGridViewButtonColumn btn1 = new DataGridViewButtonColumn();
btn1.HeaderText = "";
btn1.Text = "编辑";
btn1.Name = "edit";
btn1.Width = 40;
btn1.UseColumnTextForButtonValue = true;
this.dataGridView1.Columns.Add(btn1); DataGridViewButtonColumn btn = new DataGridViewButtonColumn();
btn.HeaderText = "";
btn.Text = "删除";
btn.Name = "del";
btn.SortMode = DataGridViewColumnSortMode.NotSortable;
btn.Width = 40;
btn.UseColumnTextForButtonValue = true;
this.dataGridView1.Columns.Add(btn); this.dataGridView1.RowPostPaint += new DataGridViewRowPostPaintEventHandler(DrawRowIndex);
}private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
{
if (dataGridView1.Columns[e.ColumnIndex].Name == "del")
{
int id = Convert.ToInt32(dataGridView1.Rows[e.RowIndex].Cells[2].Value);
dataconn.update("delete from thread where id = " + id);
MessageBox.Show("删除成功!", "提示");
page = 2;
getpagecount();
kk(0);
} if (dataGridView1.Columns[e.ColumnIndex].Name == "edit")
{
editit editfrm = new editit(int.Parse(dataGridView1.Rows[e.RowIndex].Cells[2].Value.ToString()), this);
editfrm.ShowDialog();
}
}我在一个FORM窗体中,拖入一个name为dataGridView1的dataGridView,然后绑定数据,在里面增加了两个按钮的功能,一个是编辑,还有一个是删除,不管是我点删除,还是编辑,都提示错误,形式上,好像是没有获取到对应的 ID,请问正确的获取方式是?谢谢
{
InitializeComponent(); DataSet ds = dataconn.getlist("select top " + pagesize + " content,zz from thread t,user u where u.zzid=t.zzid order by id desc");
this.dataGridView1.DataSource = ds.Tables[0].DefaultView;
this.dataGridView1.Columns[0].HeaderText = "内容";
this.dataGridView1.Columns[1].HeaderText = "作者"; DataGridViewButtonColumn btn1 = new DataGridViewButtonColumn();
btn1.HeaderText = "";
btn1.Text = "编辑";
btn1.Name = "edit";
btn1.Width = 40;
btn1.UseColumnTextForButtonValue = true;
this.dataGridView1.Columns.Add(btn1); DataGridViewButtonColumn btn = new DataGridViewButtonColumn();
btn.HeaderText = "";
btn.Text = "删除";
btn.Name = "del";
btn.SortMode = DataGridViewColumnSortMode.NotSortable;
btn.Width = 40;
btn.UseColumnTextForButtonValue = true;
this.dataGridView1.Columns.Add(btn); this.dataGridView1.RowPostPaint += new DataGridViewRowPostPaintEventHandler(DrawRowIndex);
}private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
{
if (dataGridView1.Columns[e.ColumnIndex].Name == "del")
{
int id = Convert.ToInt32(dataGridView1.Rows[e.RowIndex].Cells[2].Value);
dataconn.update("delete from thread where id = " + id);
MessageBox.Show("删除成功!", "提示");
page = 2;
getpagecount();
kk(0);
} if (dataGridView1.Columns[e.ColumnIndex].Name == "edit")
{
editit editfrm = new editit(int.Parse(dataGridView1.Rows[e.RowIndex].Cells[2].Value.ToString()), this);
editfrm.ShowDialog();
}
}我在一个FORM窗体中,拖入一个name为dataGridView1的dataGridView,然后绑定数据,在里面增加了两个按钮的功能,一个是编辑,还有一个是删除,不管是我点删除,还是编辑,都提示错误,形式上,好像是没有获取到对应的 ID,请问正确的获取方式是?谢谢
解决方案 »
- 将一个月按要求分为4周,解决即给分!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
- 在图像处理过程中绘制灰度直方图的问题
- 那位大神帮帮忙把这个XML字符串解析下
- 已得到了一个CMD窗口的句柄,怎么样可以获取该CMD窗口里的内容呢?
- 特殊字符触发事件的问题
- 关于Assembly.CreateInstance()的问题
- 打印图片锯齿问题
- 关于Excel导出错误的问题。求大神帮忙,在线等待啊。。。。。。
- Process.start()启动程序,可以正常启动程序,但是waitForExit()无法正常使用
- 怎么截取2003-12-21 12:34:23中的值为12-21 12:34?即只得月日时分
- .Net写入Windows帐户
- dateTimePicker控件与monthCalendar之间传值问题,知道的高手指点一下啊
这个sql语句有ID吗? 需要添加绑定ID
dataGridView1.Rows[e.RowIndex].Cells[2].Value这个是什么,它就是编辑列,怎么获取ID
我感觉这样做可能会好些: 你再添加一列数据库中的id,把它了隐藏起来,然后你再获取它,用这个id做为删除条件
这个值是第三个单元格绑定的值。你在绑定数据源,查看 DataSet ds = dataconn.getlist("select top " + pagesize + " content,zz from thread t,user u where u.zzid=t.zzid order by id desc");
this.dataGridView1.DataSource = ds.Tables[0].DefaultView;
前台绑定的第三列 是否是绑定id列。
this.dataGridView1.DataSource = ds.Tables[0].DefaultView;
我写成上面的格式,用
dataGridView1.Rows[e.RowIndex].Cells[2].Value 能获取到id,反而用dataGridView1.Rows[e.RowIndex].Cells[0].Value ,获取不到id,提示错误
this.dataGridView1.Columns[1].HeaderText = "内容";
this.dataGridView1.Columns[2].HeaderText = "作者";