我用VB 供参考:
Dim x, b As DataGridItem
Dim i As Integer = 0
For Each x In MyDataGrid.Items
If CType(x.FindControl("che"), CheckBox).Checked = True Then
i = i + 1
End If
Next
Select Case i
Case 0
Response.Write("<script>alert('没有选择任何行!')</script>")
Case 1
For Each b In MyDataGrid.Items
If CType(b.FindControl("che"), CheckBox).Checked = True Then
Dim idid As String = CType(b.FindControl("getvalue"), Label).Text
Dim shunxu As String = CType(b.FindControl("getshunxu"), Label).Text Response.Redirect("editmenu_zhu.aspx?zhucai=" & idid & "&shunxu=" & shunxu) End If
Next
Case Is >= 2
Response.Write("<script>alert('只能选择一行!')</script>")
End Select
Dim x, b As DataGridItem
Dim i As Integer = 0
For Each x In MyDataGrid.Items
If CType(x.FindControl("che"), CheckBox).Checked = True Then
i = i + 1
End If
Next
Select Case i
Case 0
Response.Write("<script>alert('没有选择任何行!')</script>")
Case 1
For Each b In MyDataGrid.Items
If CType(b.FindControl("che"), CheckBox).Checked = True Then
Dim idid As String = CType(b.FindControl("getvalue"), Label).Text
Dim shunxu As String = CType(b.FindControl("getshunxu"), Label).Text Response.Redirect("editmenu_zhu.aspx?zhucai=" & idid & "&shunxu=" & shunxu) End If
Next
Case Is >= 2
Response.Write("<script>alert('只能选择一行!')</script>")
End Select
{
RadioButton rb =(RadioButton)DataGrid1.Items[i].FindControl("RadioButton1");
if(rb.Checked)
{
//选中的话做的操作
}
}
{
DataGridItem myDataGridItem=drg_relation.Items[i];
CheckBox chkSelected=(CheckBox)myDataGridItem.FindControl("CheckBox1");
if(chkSelected.Checked)
{
......
}
}