unbound RadioButtonList Selected Item problem
-
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...
-
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...
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
-
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...
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.
-
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.
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; } "
-
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; } "
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.
-
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; } "
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;
-
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.
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>
-
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.