根据数据集中行项的值检查radiobutton

时间:2017-02-20 10:08:39

标签: vb.net

我想检查radiobutton,它取决于数据集中特定行项的值。

Dim adp As SqlDataAdapter = New SqlDataAdapter _
                                                ("select top 1 * from tbl_party_record order by rid desc", con)
    Dim ds As DataSet = New DataSet()
    adp.Fill(ds)
    View.TextBox1.Text = ds.Tables(0).Rows(0).Item(1)
    View.TextBox2.Text = ds.Tables(0).Rows(0).Item(2)

请将item3视为ds.Tables(0).Rows(0).Item(3)。
如果item3的值为男性,则选择单选按钮男性,如果item3的值为女性,则选择单选按钮女性,如果item3的值为other,则选择单选按钮其他。
我该怎样才能做到这一点? 谢谢你们......

1 个答案:

答案 0 :(得分:0)

我认为逻辑很简单。要在ASP.NET中设置单选按钮,可以使用Checked属性:

'First un-check them all.
radiomale.Checked = False
radiofemale.Checked = False
radioother.Checked = False

'Now set the right one checked based on the data
Dim genderValue As String = ds.Tables(0).Rows(0).Item(2)

Select Case genderValue
  Case "male"
    radiomale.Checked = True
  Case "female"
    radiofemale.Checked = True
  Case "other"
    radioother.Checked = True
End Select

如果您还没有,还应该确保所有单选按钮具有GroupName属性的相同值,以便用户不能同时选择多个单选按钮,还可以所以在下次提交时,该值会正确地发回服务器。

相关问题