mRbLACK Posted January 21, 2004 Posted January 21, 2004 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!! Quote
Administrators PlausiblyDamp Posted January 21, 2004 Administrators Posted January 21, 2004 What do you have in your Page_Load event handler? Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
Bodybag Posted January 21, 2004 Posted January 21, 2004 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 Quote 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.
mRbLACK Posted January 21, 2004 Author Posted January 21, 2004 nothing odd, just some variable inits etc. Quote
mRbLACK Posted January 21, 2004 Author Posted January 21, 2004 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 Quote
Bodybag Posted January 21, 2004 Posted January 21, 2004 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 Quote 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.
mRbLACK Posted January 21, 2004 Author Posted January 21, 2004 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... Quote
Bodybag Posted January 21, 2004 Posted January 21, 2004 Can you show me the code that you fill your radiobuttons with and the code that you check it with. Quote 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.
mRbLACK Posted January 21, 2004 Author Posted January 21, 2004 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 Quote
Administrators PlausiblyDamp Posted January 21, 2004 Administrators Posted January 21, 2004 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 Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
mRbLACK Posted January 21, 2004 Author Posted January 21, 2004 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"%> Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.