to zhongkeruanjian(编程亮子) ( ) 谢谢你的关注,INPUT=RADIO 我不想用! 你能给点例子吗?
再datagrid中添加模板列,放入radiobutton html <asp:RadioButton id="RB" runat="server" AutoPostBack="True" OnCheckedChanged="rdo_CheckedChanged"></asp:RadioButton>在代码页里加入 下面函数,控制一次只能选择一个radiobutton Protected Sub rdo_CheckedChanged(ByVal sender As Object, ByVal e As EventArgs) Dim rdo As RadioButton = CType(sender, RadioButton) Dim cell As TableCell = CType(rdo.Parent, TableCell) Dim item As DataGridItem = CType(cell.Parent, DataGridItem) Dim i As Integer For i = 0 To DataGrid1.Items.Count - 1 If i <> item.ItemIndex Then Dim r As RadioButton = CType(DataGrid1.Items(i).FindControl("rb"), RadioButton) r.Checked = False End If Next End Sub
to kerling78(kerling) 得需AutoPostBack="True"不然就不好用,可是每次都 闪一次,不太好还需要判断选的是那行呢?
如果楼主一定要在datagrid使用radiobutton,就得用kerling78(kerling)的方法在服务端 控制唯一选项,也就是说每次都闪一次。关于判断选中那行用方法: For i = 0 To DataGrid1.Items.Count - 1 Dim r As RadioButton = CType(DataGrid1.Items(i).FindControl("rb"), RadioButton) if r.Checked = True then //这是的i就是选中行数。 End If Next
大象说的对,给你个详细的 判断选定元素的循环,加到上面的函数里面就行 '取表中选定元素值 Dim j, count As Integer Dim temp As String Dim flag As Boolean flag = False count = DataGrid1.Items.Count i = 0 j = 0 Do Do While (i < count) And (flag = False) i = i + 1 Dim RB As RadioButton = CType(DataGrid1.Items(i - 1).FindControl("RB"), RadioButton) If RB.Checked = True Then flag = True textbox1.text= DataGrid1.Items(i - 1).Cells(1).Text End If Loop Loop Until (i = count) Or (flag = True)我的程序中用的就是这个。应该没问题
方法1、加一列,点击时赋值为1,其他为0,重新绑定(自己觉得比较笨,与后台交换太多)
方法2、点击后JAVASCRIPT遍历radio button,其他都置为false
如果是input=radio
我只能做到每次选择一个,不知道怎么判断选的是哪个
但radiobutton 不懂
并加注释,我太笨了,only 是个出学者
1。如果你选中一行后没有其他的操作,就可以把RADIOBUTTION的AUTOBACK设置为TRUE,并在里面做ONCHECK事件,这样只要你点中了就能回访服务器,然后用(DATAGRIDITEM)SENDER。PARENT。PARENT来得到它所在的DATAGRIDITEM
2。你为什么要判断选中了哪一个呢,你只要做的事是把TABLE中的所有的INPUT=RADIO的CHECKED设置为FALSE,然后把最新一次选中的INPUT=RADIO的CHECK设置为TRUE就行了,
页面回访后遍历RADIOBUTTON的CHECKED就行了
谢谢你的关注,INPUT=RADIO 我不想用!
你能给点例子吗?
html
<asp:RadioButton id="RB" runat="server" AutoPostBack="True" OnCheckedChanged="rdo_CheckedChanged"></asp:RadioButton>在代码页里加入 下面函数,控制一次只能选择一个radiobutton
Protected Sub rdo_CheckedChanged(ByVal sender As Object, ByVal e As EventArgs)
Dim rdo As RadioButton = CType(sender, RadioButton)
Dim cell As TableCell = CType(rdo.Parent, TableCell)
Dim item As DataGridItem = CType(cell.Parent, DataGridItem)
Dim i As Integer
For i = 0 To DataGrid1.Items.Count - 1
If i <> item.ItemIndex Then
Dim r As RadioButton = CType(DataGrid1.Items(i).FindControl("rb"), RadioButton)
r.Checked = False
End If
Next
End Sub
得需AutoPostBack="True"不然就不好用,可是每次都 闪一次,不太好还需要判断选的是那行呢?
控制唯一选项,也就是说每次都闪一次。关于判断选中那行用方法:
For i = 0 To DataGrid1.Items.Count - 1
Dim r As RadioButton = CType(DataGrid1.Items(i).FindControl("rb"), RadioButton)
if r.Checked = True then
//这是的i就是选中行数。
End If
Next
谢谢大家的关注
如果用input=radio 怎么判断选的行在数据库中的位置,因为需要对它处理
判断选定元素的循环,加到上面的函数里面就行
'取表中选定元素值
Dim j, count As Integer
Dim temp As String
Dim flag As Boolean
flag = False
count = DataGrid1.Items.Count
i = 0
j = 0
Do
Do While (i < count) And (flag = False)
i = i + 1
Dim RB As RadioButton = CType(DataGrid1.Items(i - 1).FindControl("RB"), RadioButton)
If RB.Checked = True Then
flag = True
textbox1.text= DataGrid1.Items(i - 1).Cells(1).Text
End If
Loop
Loop Until (i = count) Or (flag = True)我的程序中用的就是这个。应该没问题
那样写每次就是选一列,而且把每行的关键字(你数据库中的,保证可以知道选择的那一行)保存再hidden(bbb)中
在你的处理程序重可以得到bbb中的值,那么你就知道选的是哪一行了我做的是IC卡挂失程序,每次只能挂失一张
没有问题的
可没调试出来
你的radio行也是数据库中的列,我的不是!