Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

I have a page that has a radio button list on it...

 

<asp:radiobuttonlist ID="rdAdvanced" runat="server"  textalignment="left" > 
 <asp:ListItem Value="0" >Comments</asp:ListItem>
 <asp:ListItem Value="1" >Authors</asp:ListItem>
 <asp:ListItem Value="2" >Both</asp:ListItem>
</asp:radiobuttonlist> 

 

On the click of a button a function needs to pull the selected value from the list...BUT

for the life of me NOTHING ive tried works!! PLEASE HELP!!

Heres what I'm trying to do, do any of you know why It wont select an item i.e. even when i select an item from the list in the code it still says that nothing is selected!!

 

      Protected WithEvents rdAdvanced As  System.Web.UI.WebControls.RadioButtonList

..... (much later)

       If rdAdvanced.SelectedIndex > -1 Then
           iSearchType = rdAdvanced.SelectedItem.Value
       Else
           iSearchType = 2
       End If

 

spits out "Referenced object 'SelectedItem' has a value of 'Nothing'." no matter what i do!!

Posted

I don't know if this will help.I wrote a test centre and what i did was loop through each item in the option the radio button checking them all.

 

 

 

For count = 0 To optans.Items.Count - 1

 

dtanswers.Tables("answers").Rows(Session("curpos")).Item(count) = optans.Items(count).Selected.ToString

 

 

Next

Programmers are trying to create bigger and beter idiot proof programs.The universe is trying to create bigger and beter idiots and so far the universe is winning.
Posted

well thats the thing even though I select an item then click my button (which starts the rest) I can check each item individually and its always false , even though I can SEE that its selected!?

 

do i have to manually fire an event when an item is selected and then mark selected as true?! (sounds like madness to me!)

 

'-- From the command window

?rdAdvanced.Items.Item(0).Selected 
False
?rdAdvanced.Items.Item(1).Selected 
False
?rdAdvanced.Items.Item(2).Selected 
False

Posted

I think i might know what is wrong .Do you fill your radiobuttons before you check it.What i mean is you could be refreshing the radio buttons before you validate them.

 

use a

 

if not me.ispostback

 

radiobutton fill code.

 

end if

Programmers are trying to create bigger and beter idiot proof programs.The universe is trying to create bigger and beter idiots and so far the universe is winning.
Posted

damn, I was hopefull on that one, added if not isPostBack in function but alas no such luck the rdAdvanced.SelectedIndex is still always -1....unless I'm using the isPostBack wrong?

 

I'm thinking checkboxes are the way forward, tho one day on my death bed I know this will come back to haunt me...

 


Public Sub StartSearch()
       If Not IsPostBack Then
             blablabla...

Posted
Can you show me the code that you fill your radiobuttons with and the code that you check it with.
Programmers are trying to create bigger and beter idiot proof programs.The universe is trying to create bigger and beter idiots and so far the universe is winning.
Posted

its all above, I'm coding the buttons straight in the html, and my checking code is also above, .selectedindex... etc. or .selectedvalue but its always -1 etc.

 

bleak i know, youre probably thinking, but what on earth could be wrong its so simple...me too.....me too.....

 

         restfull sleep = large hammer + computer

  • Administrators
Posted

Just tried it here - very odd.

The buttons code behind is just

Label1.Text = RadioButtonList1.SelectedIndex.ToString

 

put a break point on the line and RadioButtonList1.SelectedIndex.ToString shows up as "2" in hte watch window. Step into the code and you still get the NullReferenceException

Posting Guidelines FAQ Post Formatting

 

Intellectuals solve problems; geniuses prevent them.

-- Albert Einstein

Posted

ok not sure i understand but thats ok

 

1) If in my items (in the html) i add "seleted" into one of the tags then, that value will always come through

 

i.e. That one is selected (Works correctly in code) BUT if i dont pre-select anything (as it were) then even though I select something on the page, when in code it comes though as -1 (instead of 2 or whatever)

 

So maybe somthing to do with how that firing off? (just a thought, dont know)

 

2) So is it or isnt it working on your side?

3) What should the values etc. on the top of my page and all that be?

 

<%@ Page Language="vb" AutoEventWireup="false" Codebehind="search.aspx.vb" Inherits="blabla.search"%>

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...