DIGIT-ARC read-only archive · snapshot: July 23, 2026

radio button checked and not checked at same time

6 posts · originally from https://geek.digit.in/community/threads/radio-button-checked-and-not-checked-at-same-time.126909/

deepakgates
deepakgates Original post #1
May 15, 2010 at 11:33 AM
okay then ....
im making dynamic sql statement
rmode is a radio button and tmode is a combo box



Private Sub bsearch_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles bsearch.Click

If rmode.Checked = True Then
ElseIf tmode.SelectedIndex = 0 Then
sql = "SELECT * FROM licdata WHERE Mode = '" & tmode.Text & "'"
ElseIf tmode.SelectedIndex = 1 Then
sql = "SELECT * FROM licdata WHERE Mode = '" & tmode.Text & "'"
End If



If rmode.Checked = True Then
MsgBox("mode")

End If






con.Open()
da = New OleDb.OleDbDataAdapter(sql, con)
da.Fill(ds, "licdb")
con.Close()
datagridresult.DataSource = ds.Tables("licdb").DefaultView
End Sub


im facing a hell of a problem
do u see two if statement
just one get executed

the second one... if i put only second then it gets executed and if only first then nothing gets executed..

WHYYYYYYYYYYYYYYYY????

PS: radiobutton is checked!!
A
May 15, 2010 at 11:14 PM
instead of elseif try to use nested if and tell the results here.
i guess u are using vb2005 or later.
deepakgates
May 16, 2010 at 9:42 AM
You are a genius....
You did it

It worked

But please tell me why it worked and what was the problem earlier...i want to know!!


am using vs2008
ruturaj3
May 16, 2010 at 9:48 AM
try this,

If rmode.Checked = True Then

If tmode.SelectedIndex = 0 Then
sql = "SELECT * FROM licdata WHERE Mode = '" & tmode.Text & "'"
End If
If tmode.SelectedIndex = 1 Then
sql = "SELECT * FROM licdata WHERE Mode = '" & tmode.Text & "'"
End If

End If
deepakgates
May 16, 2010 at 10:17 AM
ya it worked

now please tell me how what is the difference!!
A
May 16, 2010 at 3:57 PM
You are a genius....
You did it

It worked

But please tell me why it worked and what was the problem earlier...i want to know!!


am using vs2008

it is simple dude
u said that radio button is selected.
But in IF command u use ELSEIF
which will be executed only when radio button is not selected. that's why.
thx for calling me genius:-D.