Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Database & SysAdmin
  3. Database
  4. unbound RadioButtonList Selected Item problem

unbound RadioButtonList Selected Item problem

Scheduled Pinned Locked Moved Database
helpcsharpdatabasevisual-studio
8 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    amit2011
    wrote on last edited by
    #1

    i m using Visual studio 2005.here i am having a problem that i have a RadioButtonList which retrives data from sql datasource. it displays the Items correctly.Now when i try to display the SelectedItems on a label i get an error.kindly help me m stuck..m a student a really new to it.please help..thanx a lot...

    A J 2 Replies Last reply
    0
    • A amit2011

      i m using Visual studio 2005.here i am having a problem that i have a RadioButtonList which retrives data from sql datasource. it displays the Items correctly.Now when i try to display the SelectedItems on a label i get an error.kindly help me m stuck..m a student a really new to it.please help..thanx a lot...

      A Offline
      A Offline
      Ashfield
      wrote on last edited by
      #2

      Ok, a couple of things 1. This isn't a sql question, its either vb.net or c#, depending on what you are using - you state the data is being retrived correctly, so there is no sql problem 2. With no code and no error message how can anybody work out what is wrong?

      Bob Ashfield Consultants Ltd

      1 Reply Last reply
      0
      • A amit2011

        i m using Visual studio 2005.here i am having a problem that i have a RadioButtonList which retrives data from sql datasource. it displays the Items correctly.Now when i try to display the SelectedItems on a label i get an error.kindly help me m stuck..m a student a really new to it.please help..thanx a lot...

        J Offline
        J Offline
        John Gathogo
        wrote on last edited by
        #3

        Its hard to help when one has no idea what kind of error you are getting. Please paste the line that you are using to display the SelectedItems on the label or the error. It could be something minor that you are not taking into consideration.

        A 1 Reply Last reply
        0
        • J John Gathogo

          Its hard to help when one has no idea what kind of error you are getting. Please paste the line that you are using to display the SelectedItems on the label or the error. It could be something minor that you are not taking into consideration.

          A Offline
          A Offline
          amit2011
          wrote on last edited by
          #4

          the error i am getting on browser page is :- "Server Error in '/Website_dtc' Application. -------------------------------------------------------------------------------- Object reference not set to an instance of an object. Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. Exception Details: System.NullReferenceException: Object reference not set to an instance of an object. " the RadiobuttonList is databound as follows- "RadioButtonList1.DataSource = ds.Tables["temp1"]; RadioButtonList1.DataTextField = "buses"; RadioButtonList1.DataValueField = "buses"; RadioButtonList1.DataBind(); " the RadiobuttonList Item is selected as:- " protected void Button1_Click(object sender, EventArgs e) { lbltemp.Text = RadioButtonList1.SelectedItem.Text; } "

          P J 2 Replies Last reply
          0
          • A amit2011

            the error i am getting on browser page is :- "Server Error in '/Website_dtc' Application. -------------------------------------------------------------------------------- Object reference not set to an instance of an object. Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. Exception Details: System.NullReferenceException: Object reference not set to an instance of an object. " the RadiobuttonList is databound as follows- "RadioButtonList1.DataSource = ds.Tables["temp1"]; RadioButtonList1.DataTextField = "buses"; RadioButtonList1.DataValueField = "buses"; RadioButtonList1.DataBind(); " the RadiobuttonList Item is selected as:- " protected void Button1_Click(object sender, EventArgs e) { lbltemp.Text = RadioButtonList1.SelectedItem.Text; } "

            P Offline
            P Offline
            Paddy Boyd
            wrote on last edited by
            #5

            At a guess, either a) you haven't selected anything in the list or b) you rebind the list each time the page loads, thus overwriting the selection... Might want to have a look at the IsPostBack page variable.

            A 2 Replies Last reply
            0
            • A amit2011

              the error i am getting on browser page is :- "Server Error in '/Website_dtc' Application. -------------------------------------------------------------------------------- Object reference not set to an instance of an object. Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. Exception Details: System.NullReferenceException: Object reference not set to an instance of an object. " the RadiobuttonList is databound as follows- "RadioButtonList1.DataSource = ds.Tables["temp1"]; RadioButtonList1.DataTextField = "buses"; RadioButtonList1.DataValueField = "buses"; RadioButtonList1.DataBind(); " the RadiobuttonList Item is selected as:- " protected void Button1_Click(object sender, EventArgs e) { lbltemp.Text = RadioButtonList1.SelectedItem.Text; } "

              J Offline
              J Offline
              John Gathogo
              wrote on last edited by
              #6

              That error will occur if you click the button when you have not selected any of the radio buttons on the RadioButtonList1. So you need to check whether the selection has first happened. Probably using:

                      if (RadioButtonList1.SelectedIndex != -1)
                          lbltemp.Text = RadioButtonList1.SelectedItem.Text;
              
              1 Reply Last reply
              0
              • P Paddy Boyd

                At a guess, either a) you haven't selected anything in the list or b) you rebind the list each time the page loads, thus overwriting the selection... Might want to have a look at the IsPostBack page variable.

                A Offline
                A Offline
                amit2011
                wrote on last edited by
                #7

                dear paddy .. this is my Source Code for the Page-- "<%@ Page Language="C#" AutoEventWireup="true" CodeFile="searchstops_1.aspx.cs" Inherits="searchstops_1" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <!-- Design by Free CSS Templates http://www.freecsstemplates.org Released for free under a Creative Commons Attribution 2.5 License Name : Monoblock Description: A two-column, fixed-width design with dark color scheme. Version : 1.0 Released : 20080418 --> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="content-type" content="text/html; charset=utf-8" /> <title>DTC_Services</title> <meta name="keywords" content="" /> <meta name="description" content="" /> <link href="style.css" rel="stylesheet" type="text/css" media="screen" /> <script language="javascript" type="text/javascript"> <!-- function content_onclick() { } // --> </script> </head> <body> <form id="form1" runat="server"> <div id="header" style="width: 1202px"> <div id="logo"> </div> <br /> <br /> <br /> <br /> <br /> <br /> <asp:Label ID="Label1" runat="server" Font-Bold="True" Font-Size="X-Large" ForeColor="Black" Style="z-index: 100; left: 39px; position: absolute; top: 23px" Text="DELHI TRANSPORT CORPORATION"></asp:Label>         <br /> <asp:Image ID="Image2" runat="server" ImageUrl="~/PICS/logo1.gif" Style="z-index: 101; left: 1014px; position: absolute; top: 31px" />  <br />   <br /> <!-- end #search --> <br /> </div> <!-- end #header --> <div id="menu" style="width: 1202px">      <br />             <strong><span style="color: #ffffcc"> <span style="font-size: 14pt; font-family: Verdana"><a href="home.aspx">Home </a>        <a href="home.aspx">Services Offered </a>          <a href="home.aspx">Apply for DTC pass</a>  

                1 Reply Last reply
                0
                • P Paddy Boyd

                  At a guess, either a) you haven't selected anything in the list or b) you rebind the list each time the page loads, thus overwriting the selection... Might want to have a look at the IsPostBack page variable.

                  A Offline
                  A Offline
                  amit2011
                  wrote on last edited by
                  #8

                  Thanx Paddy..my problem was solved...

                  1 Reply Last reply
                  0
                  Reply
                  • Reply as topic
                  Log in to reply
                  • Oldest to Newest
                  • Newest to Oldest
                  • Most Votes


                  • Login

                  • Don't have an account? Register

                  • Login or register to search.
                  • First post
                    Last post
                  0
                  • Categories
                  • Recent
                  • Tags
                  • Popular
                  • World
                  • Users
                  • Groups