# radio button checked and not checked at same time



## deepakgates (May 15, 2010)

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
> ...




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!!


----------



## abhijangda (May 15, 2010)

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)

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)

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)

ya it worked

now please tell me how what is the difference!!


----------



## abhijangda (May 16, 2010)

deepakgates said:


> You are a genius....
> You did it
> 
> It worked
> ...


 
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.


----------

