Private Sub DataGridView1_CellClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView1.CellClick Dim iloop As Integer Dim jloop As Integer Dim intcount As Integer = 0 Dim objDt As New DataTable objDt.Columns.Add("one") objDt.Columns.Add("two") objDt.Columns.Add("three") If e.ColumnIndex = 0 Then 'checkBoxColumn列 For iloop = 0 To DataGridView1.Rows.Count - 1 If DataGridView1.Rows(iloop).Cells("checkBoxColumns").FormattedValue = True Then '判断CHECKBOXCOLUMN有没有被选中 For jloop = 0 To DataGridView1.Columns.Count - 1 objDt.NewRow() objDt.Rows(intcount).Item(jloop) = DataGridView1.Rows(iloop).Cells(jloop).Value Next intcount += 1 End If Next End If If intcount <> 0 Then DataGridView2.DataSource = objDt End If End Sub
群号:28042466
群名称:.NET 之 高手的崛起 2.
这个群适合中高级开发人员,希望大家踊跃加入.
Dim iloop As Integer
Dim jloop As Integer
Dim intcount As Integer = 0
Dim objDt As New DataTable
objDt.Columns.Add("one")
objDt.Columns.Add("two")
objDt.Columns.Add("three")
If e.ColumnIndex = 0 Then 'checkBoxColumn列
For iloop = 0 To DataGridView1.Rows.Count - 1 If DataGridView1.Rows(iloop).Cells("checkBoxColumns").FormattedValue = True Then '判断CHECKBOXCOLUMN有没有被选中
For jloop = 0 To DataGridView1.Columns.Count - 1
objDt.NewRow()
objDt.Rows(intcount).Item(jloop) = DataGridView1.Rows(iloop).Cells(jloop).Value Next
intcount += 1
End If Next
End If
If intcount <> 0 Then
DataGridView2.DataSource = objDt
End If
End Sub
public void btn_Click(object sender,EventArgument e)
{
DataTable dt=new DataTable();
dt.Columns.Add("表头1");
dt.Columns.Add("表头2"); //你有几多列数据就加几多列
for (int i = 0; i < gv1.Rows.Count; i++)
{
CheckBox chkMusic = (CheckBox)gv1.Rows[i].FindControl("chkMusic");
if (chkMusic.Checked)
{
dr=dt.NewRow();
int musicID=int.Parse(gv1.Rows[i].Cells[0].Text.ToString());//把你选种的ID读出来了,再到数据库根据ID查
//查询的省了
whlie(sdr.Read())
{
dr[0]=sdr[0].toString();
dr[1]=sdr[1].tostring();
//你有几多列数据就加几多列
}
dt.Rows.Add(dr)
}
}
this.gv1.DataSource=dt;
this.gv1.DataBind();
}
你复选框肯定绑定了,每一行的ID吧在Button里写一个前台事件,因为前台事件运行在服务器事件之前.前台事件遍历checkbox取得相应的值生成一个有规律的串(1,2,3,4,.....)
利用这个串在查一下数据绑到下面的GridView
把这两个函数加到页面上,认真读一下吧,我个是我们的项里的代码,很实用,外面没有的
<script language="javascript">
//获取选择的ID
function getSelectedIDs(dataGrid)
{
if (dataGrid == null)
return "";
var selectedID = "";
var id = dataGrid.document.getElementsByTagName("input");
//var id = dataGrid.document.all.tags("input");
for (var i = 0;i < id.length;i++)
{
if (id[i].type == "checkbox" && id[i].checked == true && id[i].value != "")
selectedID += id[i].value + ",";
}
if (selectedID.length > 0)
{
selectedID = selectedID.substr(0,selectedID.length - 1);
}
return selectedID;
}function DeleteRows() //一次删除多条记录,其实和你的同理
{ //dtg_search : 这个是你的GridView的id
var selectedIDs = getSelectedIDs(document.getElementById("dtg_search"))
if (selectedIDs == null || selectedIDs == "")
{
alert("请您选择要删除的项。");
return false;
}
if (confirm("确定删除?"))
{
document.getElementById("hdn_selectedIDs").value = selectedIDs;
return true;
}
else
{
return false;
}
}
</script>