用FindControl("CheckBoxID")的方法遍历控件。private void delButton_Click(object sender, System.EventArgs e)
{
System.Web.UI.WebControls.CheckBox checkBox;
for( int i = 0; i < DataGrid1.Items.Count; i ++ )
{
//查找CheckBox控件
checkBox = (CheckBox)DataGrid1.Items[i].FindControl("CheckBox1"); if(checkBox!=null && checkBox.Checked)
{
checkBoxID = DataGrid1.Items[i].Cells[1].Text; CB_ItemName = DataGrid1.Items[i].Cells[2].Text;
delDataGrid();
}
}
//重新绑定DataGrid
BindData();
}
{
System.Web.UI.WebControls.CheckBox checkBox;
for( int i = 0; i < DataGrid1.Items.Count; i ++ )
{
//查找CheckBox控件
checkBox = (CheckBox)DataGrid1.Items[i].FindControl("CheckBox1"); if(checkBox!=null && checkBox.Checked)
{
checkBoxID = DataGrid1.Items[i].Cells[1].Text; CB_ItemName = DataGrid1.Items[i].Cells[2].Text;
delDataGrid();
}
}
//重新绑定DataGrid
BindData();
}
if CType(dgMisBase.Items(行号).Cells(列号).FindControl("checkbox的id"), RadioButton).Checked = true then
c#
if( ((CheckBox)DataGrid1.Items[行号].Cells[列号].FindControl("CheckBox的id")).checked = true )
{
//处理
}
CType(dgMisBase.Items(行号).Cells(列号).FindControl("checkbox的id"), RadioButton).Checked 就是其状态值(true 或 false)
c#中
((CheckBox)DataGrid1.Items[行号].Cells[列号].FindControl("CheckBox的id")).checked
是其状态值
{
CheckBox check=(CheckBox)rowItem.FindControl("CheckBox2");
//
if((check.Checked) {
…… }
}
//这个是CheckBox,你参考一下!
vb.net 中 RadioButton 改为:CheckBox
注:dgMisBase 是dataGrid 的id
我用的就是xrascal(横刀夺爱)的做法。
没有问题的。 我在给你一个我在使用的程序,用来判断是否全部选中。 '检查数据表格是否全部选中
Private Sub btn_check_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn_check.Click
Dim i As Integer
'设置标志位,为0时候,表示没有选中一行。
Dim flag As Integer
'从第一行到最后一行遍历整个数据表格
For i = 0 To Me.myDataGrid.Items.Count - 1
Dim checkbox1 As CheckBox
checkbox1 = Me.myDataGrid.Items(i).FindControl("CheckBox1")
If (checkbox1.Enabled = True And checkbox1.Checked) Then
Dim checkboxid As String
checkboxid = Me.myDataGrid.Items(i).Cells(0).Text
flag += 1
End If
Next
'如果选中列数小于数据行数。则表示没有全部选中
If flag < Me.myDataGrid.Items.Count Then
Me.message.Text += "没有全部选中,当前选中了" + flag.ToString + "个"
Else
Me.message.Text += "全部选中了"
End If End Sub
在vb.net中vb.net
CType(dataGrid.Items(行号).Cells(列号).FindControl("checkbox的id"), CheckBoxList).SelectedIndex 就是其值
c#中
((CheckBoxList)DataGrid1.Items[行号].Cells[列号].FindControl("CheckBoxList的id")).SelectedIndex
是其状态值假如 是多选的话 可以根据实际情况 你自己改一下 就可以了