473,803 Members | 3,380 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Set dropdownlist value

tfs
I have a dropdownlist that I was setting to an index (which happened
to be the same as the value). I changed this to a character as that
is what I want to have in my database.

<asp:dropdownli st
style="border:n one" id="recurrenceT ype"
runat="server">
<asp:listitem value="N"
None</asp:listitem> <asp:listitem value="M"Monthly</asp:listitem> <asp:listitem value="P"Periodic</asp:listitem>

</asp:dropdownlis t>
I was setting the value before (when the value was "0", "1" and "2").
It used to work like this:

recurrenceType. SelectedIndex = objDataReader(" recurrenceType" )

How would I set it with the value set to a char?

Thanks,

Tom.
Posted Via Usenet.com Premium Usenet Newsgroup Services
----------------------------------------------------------
** SPEED ** RETENTION ** COMPLETION ** ANONYMITY **
----------------------------------------------------------
http://www.usenet.com
Nov 18 '05 #1
6 4017
tfs
I have tried all kinds of ways to get this to work and keep getting
strange (at least to me) results.

If I do a viewsource of the above statement (my last post):

recurrenceType. SelectedItem.va lue = "P"

I get the following:

<select name="recurrenc eType" id="recurrenceT ype"
style="border:n one">
<option selected="selec ted" value="P">None</option>
<option value="M">Month ly</option>
<option value="P">Perio dic</option>
</select>

It seems to change the value, which I guess is what I am saying - but
this is how I saw it selected in one example. I am trying to get it
to move the selected="selec ted" to the 3rd option and it isn't doing
it.

I then tried:

recurrenceType. Items.FindByVal ue("P").selecte d = true

And got the following error:

A DropDownList cannot have multiple items selected.
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.Web.Http Exception: A DropDownList
cannot have multiple items selected.

Source Error:
Line 132: </table>
Line 133:
Line 134: <form runat="server">
Line 135: <table align="center">
Line 136: <tr
valign="baselin e">
This is driving me crazy.

Thanks,

Tom.
Posted Via Usenet.com Premium Usenet Newsgroup Services
----------------------------------------------------------
** SPEED ** RETENTION ** COMPLETION ** ANONYMITY **
----------------------------------------------------------
http://www.usenet.com
Nov 18 '05 #2
tfs
I just tried this:

recurrenceType. SelectedItem.va lue = "P"

The display on the screen is still "None".

Thanks,

Tom.
Posted Via Usenet.com Premium Usenet Newsgroup Services
----------------------------------------------------------
** SPEED ** RETENTION ** COMPLETION ** ANONYMITY **
----------------------------------------------------------
http://www.usenet.com
Nov 18 '05 #3
The syntax should be something close to this:

recurrenceType. SelectedItem=re currenceType.It ems.FindByValue ("P")

--
I hope this helps,
Steve C. Orr, MCSD, MVP
http://Steve.Orr.net

"tfs" <tf*@dslextre me-dot-com.no-spam.invalid> wrote in message
news:40******** **@Usenet.com.. .
I have a dropdownlist that I was setting to an index (which happened
to be the same as the value). I changed this to a character as that
is what I want to have in my database.

<asp:dropdownli st
style="border:n one" id="recurrenceT ype"
runat="server">
<asp:listitem value="N"
None</asp:listitem>

<asp:listitem value="M"
Monthly</asp:listitem>

<asp:listitem value="P"
Periodic</asp:listitem>

</asp:dropdownlis t>
I was setting the value before (when the value was "0", "1" and "2").
It used to work like this:

recurrenceType. SelectedIndex = objDataReader(" recurrenceType" )

How would I set it with the value set to a char?

Thanks,

Tom.
Posted Via Usenet.com Premium Usenet Newsgroup Services
----------------------------------------------------------
** SPEED ** RETENTION ** COMPLETION ** ANONYMITY **
----------------------------------------------------------
http://www.usenet.com

Nov 18 '05 #4
I think what you are looking for is -
((ListItem)recu rrenceType.Item s.FindByValue(" P")).Selecte d = true;

Bobby Ryzhy
bo***@weekendte ch.net
http://www.weekendtech.net
On Tue, 6 Jul 2004 14:43:16 -0700, "Steve C. Orr [MVP, MCSD]"
<St***@Orr.ne t> wrote:
The syntax should be something close to this:

recurrenceType .SelectedItem=r ecurrenceType.I tems.FindByValu e("P")


Nov 18 '05 #5
Yes, I believe that is more precise.

"Bobby Ryzhy" <br****@hotmail .com> wrote in message
news:vt******** *************** *********@4ax.c om...
I think what you are looking for is -
((ListItem)recu rrenceType.Item s.FindByValue(" P")).Selecte d = true;

Bobby Ryzhy
bo***@weekendte ch.net
http://www.weekendtech.net
On Tue, 6 Jul 2004 14:43:16 -0700, "Steve C. Orr [MVP, MCSD]"
<St***@Orr.ne t> wrote:
The syntax should be something close to this:

recurrenceType .SelectedItem=r ecurrenceType.I tems.FindByValu e("P")

Nov 18 '05 #6
tfs
SelectValue was it.

Here is what I did that works fine.
recurrenceType. SelectedValue =
objDataReader(" recurrenceType" )
recurrenceDispl ay.text = recurrenceType. SelectedItem.te xt

<td nowrap align="right">R ecurrance:</td>
<td>
<asp:label id="recurrenceD isplay"
runat="server" />
<asp:dropdownli st style="visibili ty:hidden"
id="recurrenceT ype" runat="server">
<asp:listitem value="N"
None</asp:listitem> <asp:listitem value="M"Monthly</asp:listitem> <asp:listitem value="P"Periodic</asp:listitem>

</asp:dropdownlis t>
</td>
Thanks,

Tom
Posted Via Usenet.com Premium Usenet Newsgroup Services
----------------------------------------------------------
** SPEED ** RETENTION ** COMPLETION ** ANONYMITY **
----------------------------------------------------------
http://www.usenet.com
Nov 18 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
1146
by: Viktor Popov | last post by:
Hi, I'd like to ask how could be taken the value from DropDownList and to appropriate it to cmd.Parameters.Value = DropDownList1...... I know that it must be something like this above. Could you help me!
1
1449
by: Daniel Doyle | last post by:
I have cut my page down to the simple code below. The problem is when the user selects a number from the list I want this number to remain selected after the response.redirect, but the first item in the list is always selected. I have another page that looks the same and works but I can't understand why this one doesn't. Please help. Thanks. Dan. <%@ Page Language="VB" %>
1
1436
by: Vi | last post by:
Hi, I have a pop-up window in which I have 3 WebControls.DropDownList controls. I make my selections and when I submit the page, in the code behind page one control has the right value for SelectedIndex and SelectedValue properties, but the other two controls have values like I did not make any selections in them. The only difference between the controls is that the one that's working is defined in the page using <asp:ListItem...
1
2097
by: Geoffrey van den Ouden | last post by:
I'm converting this project from ASP.NET 1.1 to 2.0, and the thing I came across is that my dropdownlist no returns the content of the Value property in a correct way. I'm not using a direct Database connection or anything, most of my dropdownlists are filled with values from static singletons that are running or just some code that is generated at page_load. The basic thing is that on page_load I always create a ListItemCollection...
2
7789
by: keithb | last post by:
I have dropdown list in a gridview column edit template. It works OK, except when I edit a row, the dropdown list does not initialize to the existing value that shows in the textbox that displays in the item template. I tried to initialize the selected value of the dropdown list with some lines of code in the grid_RowEditing event but I get an error that I do not understand. The error occurs at this line of code: String DelID =...
0
1192
by: Jon Paal | last post by:
--dropdownlist value isn't being saved to database from FORMVIEW --field PriorityID is datatype "number" (integer) what's missing ???? '=========code============= <asp:Content ID="Content1" ContentPlaceHolderID="PageContentPlaceHolder" runat="Server"> <asp:AccessDataSource id="DataSource1" Runat="Server"
0
1537
by: dit | last post by:
Hello, I found this piece of code for selecting a dropDownlist value in a repeater: <aspropDownList id=ddl DataSource="<%# SourceTable %>" runat="server" DataTextField="Name" DataValueField="Code" SelectedIndex='<%# ListIndex((DropDownList)target,DataBinder.Eval( Container.DataItem,"Code")) %>'></aspropDownList> SourceTable should be protected property in your page and its type is
2
2676
by: rob | last post by:
Hi, I have a button whose PostBackUrl should include a value from a dropdownlist on the same page. Should I do that in the button's on click event? What I'd like to end up with is a post back url that looks like the following: PostBackUrl=somepage.aspx?param=<valuewhere <valuecomes from the currently selected item in the list. Thanks, Rob
2
9292
by: uicouic | last post by:
Hi all. I need help about this particular aspect. In a webform I have an <asp:textbox> (txtName) and <asp:DropDownList> (lstSchool) with 2 values inside. I have typed in a value for the textbox. When I select an option from the dropdownlist, I would like that value(String) to be concatenated with the textbox's value. How do I achieve this in JavaScript? (Microsoft Visual Studio 2005) Any help/advice appreciated. Thanks.
0
9703
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
1
10295
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10069
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9125
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7604
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5501
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4275
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3799
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2972
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.