如何使用带有CheckBox的dataGridView将已检查的dataGridview列数据发送到SQL DB [英] How to send the checked Rows of dataGridview columns data To The SQL DB using dataGridView with CheckBox

查看:69
本文介绍了如何使用带有CheckBox的dataGridView将已检查的dataGridview列数据发送到SQL DB的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

//点击按钮

foreach(GridView1.Rows中的GridViewRow行)

{

CheckBox chk = row.Cells [0 ] .FindControl(chkSelect);

if(chk!= null && chk.Checked)

{

//插入table1 values(''+ row.Cells [0] .text +'',''+ row.Cells [1] .text +'')

}

}



这里是用C#web应用程序中的CheckBox为GridView编写的代码_



但是我想在Windows应用程序中执行此任务_



[在dataGridview中我在每行添加了复选框_

让我举个例子_

i在dataGridView中有四列(srno,name,id)和

在行的结尾列我拿了复选框

来check_



,任务是,

只有dataGridView的已检查行数据必须保存

in数据库通过按钮单击事件使用sql查询那个_]



帮我Me_ :)

完成这个任务_



谢谢_

//on button click
foreach (GridViewRow row in GridView1.Rows)
{
CheckBox chk = row.Cells[0].FindControl("chkSelect");
if (chk != null && chk.Checked)
{
//insert into table1 values(''" + row.Cells[0].text + "'' ,''" + row.Cells[1].text + "'' )
}
}

Here Is The code written for GridView with CheckBox in C# web application_

But i want to perform this Task In Windows Application_

[In dataGridview i have added check boxes in each row_
let me give an example_
i have four columns in dataGridView(srno,name,id) and
at the end column of the row i took the checkbox
to check_

and the task is,
only the checked rows data of the dataGridView must be saved
in to the DB by a button Click event using sql Query in That_]

Help Me_ :)
TO Complete This Task_

Thank you_

推荐答案

检查:



private void button1_Click(object sender,System.EventArgs e)

{

foreach(DataGridViewRow dataGridView1.Rows中的行)

{

DataGridViewCheckBoxCell checkBox = row.Cells [ check]为DataGridViewCheckBoxCell;

if(checkBox!= null && checkBox.Value!= null &&(bool)checkBox.Value)

{

//插入table1值(''+ row.Cells [0] .text +'',''+ row.Cells [1] .text +'')

}





}





}





- 如果你满意我的回答请标记。
Check It:

private void button1_Click(object sender, System.EventArgs e)
{
foreach (DataGridViewRow row in dataGridView1.Rows)
{
DataGridViewCheckBoxCell checkBox = row.Cells["check"] as DataGridViewCheckBoxCell;
if (checkBox != null && checkBox.Value != null && (bool)checkBox.Value)
{
//insert into table1 values(''" + row.Cells[0].text + "'' ,''" + row.Cells[1].text + "'' )
}


}


}


--if u satified my answer pls mark it.


这篇关于如何使用带有CheckBox的dataGridView将已检查的dataGridview列数据发送到SQL DB的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆