473,386 Members | 1,694 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

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:dropdownlist
style="border:none" id="recurrenceType"
runat="server">
<asp:listitem value="N"
None</asp:listitem> <asp:listitem value="M"Monthly</asp:listitem> <asp:listitem value="P"Periodic</asp:listitem>

</asp:dropdownlist>
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 3999
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.value = "P"

I get the following:

<select name="recurrenceType" id="recurrenceType"
style="border:none">
<option selected="selected" value="P">None</option>
<option value="M">Monthly</option>
<option value="P">Periodic</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="selected" to the 3rd option and it isn't doing
it.

I then tried:

recurrenceType.Items.FindByValue("P").selected = 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.HttpException: 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="baseline">
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.value = "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=recurrenceType.Items.F indByValue("P")

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

"tfs" <tf*@dslextreme-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:dropdownlist
style="border:none" id="recurrenceType"
runat="server">
<asp:listitem value="N"
None</asp:listitem>

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

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

</asp:dropdownlist>
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)recurrenceType.Items.FindByValue("P")). Selected = true;

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

recurrenceType.SelectedItem=recurrenceType.Items. FindByValue("P")


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

"Bobby Ryzhy" <br****@hotmail.com> wrote in message
news:vt********************************@4ax.com...
I think what you are looking for is -
((ListItem)recurrenceType.Items.FindByValue("P")). Selected = true;

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

recurrenceType.SelectedItem=recurrenceType.Items. FindByValue("P")

Nov 18 '05 #6
tfs
SelectValue was it.

Here is what I did that works fine.
recurrenceType.SelectedValue =
objDataReader("recurrenceType")
recurrenceDisplay.text = recurrenceType.SelectedItem.text

<td nowrap align="right">Recurrance:</td>
<td>
<asp:label id="recurrenceDisplay"
runat="server" />
<asp:dropdownlist style="visibility:hidden"
id="recurrenceType" runat="server">
<asp:listitem value="N"
None</asp:listitem> <asp:listitem value="M"Monthly</asp:listitem> <asp:listitem value="P"Periodic</asp:listitem>

</asp:dropdownlist>
</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
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...
1
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...
1
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...
1
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...
2
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...
0
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"...
0
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"...
2
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...
2
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...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.