Selecting the default selected Item in RadiobuttonList

Is it possible to set the default item selected of radiobuttonlist from code behind while  he page loads. I have been trying this with its method and properties but yet to get it right: this is the code

<asp:RadioButtonList ID="rdlSetting" runat="server" RepeatColumns="2" RepeatDirection="Vertical" RepeatLayout="Table">
<asp:ListItem Text="Public" Value="0"></asp:ListItem>
<asp:ListItem Text="Private" Value="1"></asp:ListItem>
</asp:RadioButtonList>

from COde behind

on Page_Load

if Not page.ispostback then

    if(iObj.isprivate = true) then

    rdlSetting.Items.FindByValue(0).selected = true

   else

   rdlSetting.Items.FindByValue(1).selected = true

end if

pls help
 

 

0
Contributor
9/11/2007 12:00:53 PM
asp.net.web-forms 93655 articles. 6 followers. Follow

2 Replies
2026 Views

Similar Articles

[PageSpeed] 19

If (iObj.isprivate = True) Then
    rdlSetting.SelectedValue = "0"
Else
    rdlSetting.SelectedValue = "1"
End If

-=JW=-
0
jamezw
9/11/2007 12:56:55 PM

I have also this kind of problem.

here is my Code:

 public partial class img_Registrace : System.Web.UI.Page
{
    public string myMail;
    public string CurrentUser;
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Profile.IsAnonymous)
        {
            CurrentUser = HttpContext.Current.User.Identity.Name;
            myMail = Membership.GetUser(CurrentUser).Email;
            ProfileCommon p = (ProfileCommon)ProfileCommon.Create(CurrentUser, true);
            ((TextBox)LoginView2.FindControl("reg_jmeno")).Text = p.Jmeno;
            ((TextBox)LoginView2.FindControl("reg_prijmeni")).Text = p.Prijmeni;
            ((TextBox)LoginView2.FindControl("reg_datnar")).Text = p.Narozeni;
            ((RadioButtonList)LoginView2.FindControl("RadioButtonList1")).Items.FindByValue(p.Pohlavi).Selected = true;
            ((TextBox)LoginView2.FindControl("reg_ulice")).Text = p.Ulice;
            ((TextBox)LoginView2.FindControl("reg_obec")).Text = p.Obec;
            ((TextBox)LoginView2.FindControl("reg_psc")).Text = p.PSC.ToString();
            ((DropDownList)LoginView2.FindControl("reg_region")).SelectedValue = p.Region;
            ((TextBox)LoginView2.FindControl("reg_telefon")).Text = p.Telefon.ToString()
        }
    }
    protected void CreateUserWizard1_CreatingUser(object sender, LoginCancelEventArgs e)
    {
        CreateUserWizard cuw = (CreateUserWizard)sender;
        cuw.Email = cuw.UserName;

        ProfileCommon p = (ProfileCommon)ProfileCommon.Create(cuw.UserName, true);
        p.Jmeno = ((TextBox)LoginView2.FindControl("reg_jmeno")).Text;
        p.Prijmeni = ((TextBox)LoginView2.FindControl("reg_prijmeni")).Text;
        p.Narozeni = ((TextBox)LoginView2.FindControl("reg_datnar")).Text;
        p.Pohlavi = ((RadioButtonList)LoginView2.FindControl("RadioButtonList1")).SelectedValue;
        p.Ulice = ((TextBox)LoginView2.FindControl("reg_ulice")).Text;
        p.Obec = ((TextBox)LoginView2.FindControl("reg_obec")).Text;
        p.PSC = Convert.ToInt32(((TextBox)LoginView2.FindControl("reg_psc")).Text);
        p.Region = ((DropDownList)LoginView2.FindControl("reg_region")).SelectedValue;
        p.Telefon = Convert.ToInt32(((TextBox)LoginView2.FindControl("reg_telefon")).Text);
        p.Save();
    }
}

 Gives me error :  Object Reference not set to an instance of an object

help needed.
 

0
Bordeaux
11/21/2007 12:26:17 PM
Reply:

Similar Artilces:

Dynamic DropDownList Default Selected Item Does Not Select Default Item
I have some dynamic listbox code that creates a listbox based on information stored in a database. The database access works fine. The only issue is that when I use the lbNew.Items.FindByValue(...).Selected = True line, no default select is made. The listbox just defaults to the first item in the list.lbNew = New DropDownList ' Scans for the list source. ' If "values_table" returns the first character = '@', ' then a table is the datasource. strDataSourceTable = Nothing strDataSourceTable = objDataReader.Item("values_table") ' If there is a data list, display the item, else ig...

Why is the select saying selected after an item is selected?
This was a whitelisting issue due to a software upgrade at hostgator..  Nothing wrong with my code..Scot King SEO Software Tool | Search Engine Optimization"Get your page rank high"  huh? It is smart to put your question in the body and not just in the title. Have no idea what your question is or if it even a question.Eric Pascarello.com | Twitter epascarello | LinkedIn use thisddl.options[ddl.selectedIndex].selected = false; //Clear the selection ddl.options[1].selected = trueMAKMark as Answer if this reply helps youMVP ASP/ASP.NetASP.Net Hosting : Host DepotMy Sit...

How do .NET Developers handle the need for a RadioButtonList to default to "no selected values" until user selects one?
If I am trying to capture user information in a database through a radiobuttonlist without giving any preselected items, it seems the only possible way to do this is to set the default value of the database to -1 and bind it to the selectedindex value.  However, when the user starts making selections, the selectedindex value is NOT the same as the selectedvalue that the user is clicking.  So the database is collecting selectedindex value.  Is there a way to handle this scenerio correctly?  I originally had the selectedvalue bound to the database, but could not g...

Load Text box of one web form with selected list item of list box of another web form
one help please Problem is i have two web forms  1.  ForiegnkeyTest.aspx  2. foroginkeytable.aspx   step 1 1 ForiegnkeyTest.aspx one web form <head runat="server"><script language="javascript" type="text/javascript">   function popWin()   {         var confirmWin = null;      confirmWin = window.open('foroginkeytable.aspx','anycontent',   'width=455,height=435,status');   }  </script> &...

Getting the Selected Item of dropdownlist inside Web User Control on a Web Form
Ive got a dropdownlist control inside a web user control called Entity.ascx. This web user control is on a webform.aspx. In Entity.ascx class I created a SelectedEntity property that returns the selected item in the dropdownlist. Inside webform.aspx when btnGo is pushed I set a string and pass it in the url. I am trying to get the entity they selected via the property (SelectedEntity) inside Entity.ascx. As the SelectedEntity property tries to return the selected item in the dropdownlist I get this error: System.NullReferenceException: Object reference not set to an instance...

superreview requested: [Bug 112281] ctrl+shift+click whle making range selections in form <select> shouldn't wipe out other selected items : [Attachment 135533] Proposed patch
Boris Zbarsky (real world intrudes) <bz-vacation@mit.edu> has asked Robert O'Callahan <roc@ocallahan.org> for superreview: Bug 112281: ctrl+shift+click whle making range selections in form <select> shouldn't wipe out other selected items http://bugzilla.mozilla.org/show_bug.cgi?id=112281 Attachment 135533: Proposed patch http://bugzilla.mozilla.org/attachment.cgi?id=135533&action=edit ------- Additional Comments from Boris Zbarsky (real world intrudes) <bz-vacation@mit.edu> roc, what do you think? ...

superreview granted: [Bug 112281] ctrl+shift+click whle making range selections in form <select> shouldn't wipe out other selected items : [Attachment 135533] Proposed patch
Robert O'Callahan <roc@ocallahan.org> has granted Boris Zbarsky (real world intrudes) <bz-vacation@mit.edu>'s request for superreview: Bug 112281: ctrl+shift+click whle making range selections in form <select> shouldn't wipe out other selected items http://bugzilla.mozilla.org/show_bug.cgi?id=112281 Attachment 135533: Proposed patch http://bugzilla.mozilla.org/attachment.cgi?id=135533&action=edit ------- Additional Comments from Robert O'Callahan <roc@ocallahan.org> looks quite straighforward :-) ...

How to use Select case statement to select web form controls
Hi; I don't know why I can't conceptionalize  this but I want to take these if statements and put them in a select case. I am testing for multiple selection from several DDLs on my web form.   If DropDownList1.SelectedIndex > -1 And DropDownList2.SelectedIndex > 0 Then If Me.CheckBox1.Checked Then ObjectDataSource1.FilterExpression = "assignee = {0} AND assignor = {1}" Else ObjectDataSource5.FilterExpression = "assignee = {0} AND assignor = {1}" End If End If If DropDownList1.SelectedIndex > -1 And DropDownList3.SelectedIndex >...

How to get selected item(s) from a select form with Intraweb? [Edit]
Hi Everyone! I am going to convert our Delphi Client/Server Applications to Intraweb applications. I never use Intraweb before this month. Can anyone tell me how to do the folling with Intraweb? Any Sample do that? ---------------------------------------------------------------------------------------- Open a form(contain a Grid), and select one or more items, then bring the selected item(s) back to calling form. ---------------------------------------------------------------------------------------- Thanks to all. from: Slong Tseng. Edited by: Big Two on Jun 8, 2014 6:10 PM ...

SELECT from SELECT
Hi! I remember seeing an example where you can do a select from a nested select, but I cannot seem to make it work. So it would be something like this: select max( name ) from ( select name from customer union select name from vendor ) Was I dreaming I saw that? Thanks! D In article <4500243f@forums-2-dub>, daniel_AT_infrontsoftware_DOT_com@N0SPAM.com says... > Hi! > > I remember seeing an example where you can do a select from a nested > select, but I cannot seem to make it work. No, you weren't. Try (UNTESTED!) adding a...

Submit web form with a RadioButtonList Control not selected.
How can one set up a web form that has some radiobuttonlist controls so the form can submit without ALL of the radiobuttonlist controls having to be selected? Everything works fine if ALL of the radiobuttonlist controls have been selected at least once. Any assistance is appreciated. Please let me know if additional info is needed. This is the error I am receiving: Exception Details: System.NullReferenceException: Object reference not set to an instance of an object. Test the object before usingi it... If myobj IsNot Nothing Then 'Process the control value Else ...

Can a RadioButtonList default to "no selected values" until user selects one?
I am using a RadioButtonList1 on an ASP.NET web page that is bound to a database table.  I have the database table set to create a default value of 1.  This defaults my radio button to 1.  When I remove the default value of 1 from the database and run the application, it complains that it can NOT find a value in the list (which makes sense).  The list selection is also bound to a database, but I do not want to create another value just here for the default.   Is there a way to set the RadioButtonList to NOT have any default selections until a selection is m...

Forms , Select and option selected.
Name: Jirrick Email: jurahudecatgmaildotcom Product: Firefox Release Candidate Summary: Forms , Select and option selected. Comments: I've found problem with SELECTED option in <select> forms. I wanted to use pre-selected option in my form , but when I used the Firefox 3 RC1 to render it there wasn't any preselected item. I tried to rewrite code ( use selected="selected" ) , but still no effect. I was confused and tried to use others viewers ( IE 8 , OP 9 , Konqueror ) and the pre-selected item worked well in these browsers. The bug has to be in FF 3 ...

Update selected RadioButtonList value to a label in a web form
 I have a web form and when you click a button, a ModalPopUp-control opens. It contains a RadioButtonList. All I want is that when user selects one of the RadioButtons in ModalPopup, it's value is updated back to a web form (label-control) using codebehind.  When I click the Update-button on the ModalPopup, the correct value (RadioButtonList's SelectedItem.Text) is passed and set to label's text-property, but label remains empty on the web form so it won't update.  Anyone, please? Hi k000der, From your description, I understand that you use the ModalPopupE...

Web resources about - Selecting the default selected Item in RadiobuttonList - asp.net.web-forms

A2ZMenu tutorial index page
A2Zmenu.Com Blog Tutorials Online Exam Ask Question Utility Fun @ Work Funda Contact Us About Us Loading Test Your Skill Q. Out of Boxing and ...

Quick Answers - CodeProject
Questions - Free source code and tutorials for Software developers and Architects.; Updated: 1 Jun 2012

DaniWeb Solved Articles - Technology Publication Meets Social Media
An online discussion community of IT professionals. Forums to get free computer help and support. We are a social technology publication covering ...

.NET sample code - developer Fusion
Discover the very latest .NET sample code Out of the box, the ASP.NET list controls (CheckBoxList, RadioButtonList, DropDownList) only support ...

ConditionalRequiredTextValidator Control
The ConditionalRequiredTextValidator control allows you to specify a CheckBox, RadioButton, CheckBoxList, RadioButtonList, DropDownList, or ListBox ...

ASP.NET 4 and Visual Studio 2010 Web Development Overview : The Official Microsoft ASP.NET Site
This document provides an overview of many of the new features for ASP.NET that are included in the.NET Framework 4 and in Visual Studio 2010. ...

Gaiaware - Gaia Ajax
Home Samples Download Free Trial Buy from $195 Login Download Free Trial ASP.NET Done Right 6 reasons to use Gaia Ajax? 40 UI controls 10 aspects/behaviors ...

A2ZMenu utilities index page
A2Zmenu.Com Blog Tutorials Online Exam Ask Question Utility Fun @ Work Funda Contact Us About Us Loading Online Tool Title Description Rating ...

Online Exam papers index page
A2Zmenu.Com Blog Tutorials Online Exam Ask Question Utility Fun @ Work Funda Contact Us About Us Loading Test Your Skill Q. Out of Boxing and ...

A2ZMenu Experts Comment
A2ZMenu team is committed in providing solution in various technologies through blogs, tutorials, Q & A etc. Our objective is to give a knowledge ...

Resources last updated: 12/18/2015 2:01:58 PM