473,320 Members | 2,071 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,320 software developers and data experts.

Make a value the default in a databound dropdown

I have a databound dropdown in my page. I want to make one of the
values the default value. Any ideas?

Just to explain further, I have also appended one item to the dropdown,
using the AppendDataBoundItems="True" property of the dropdown.
Unfortunately the item I have appended to the dropdown has become the
default value of the dropdown list which is not what I want.

Kind regards,

Steve.

Sep 7 '06 #1
3 1226
myDropDown.SelectedIndex =
myDropDown.Items.IndexOf(myDropDown.Items.FindByVa lue("yourDefaultValue"))

you can also use FindByText which uses the text, instead of the value.

Karl

--
http://www.openmymind.net/
http://www.codebetter.com/
"Steve" <ba****@iranmania.comwrote in message
news:11**********************@b28g2000cwb.googlegr oups.com...
>I have a databound dropdown in my page. I want to make one of the
values the default value. Any ideas?

Just to explain further, I have also appended one item to the dropdown,
using the AppendDataBoundItems="True" property of the dropdown.
Unfortunately the item I have appended to the dropdown has become the
default value of the dropdown list which is not what I want.

Kind regards,

Steve.

Sep 7 '06 #2
Thank you for this Karl.

Should I put this code in the page load event in page behind or can I
somehow put it as a parameter in between the dropdown tags in the page
itself.

Kind regads,

Steve
Karl Seguin [MVP] wrote:
myDropDown.SelectedIndex =
myDropDown.Items.IndexOf(myDropDown.Items.FindByVa lue("yourDefaultValue"))

you can also use FindByText which uses the text, instead of the value.

Karl

--
http://www.openmymind.net/
http://www.codebetter.com/
"Steve" <ba****@iranmania.comwrote in message
news:11**********************@b28g2000cwb.googlegr oups.com...
I have a databound dropdown in my page. I want to make one of the
values the default value. Any ideas?

Just to explain further, I have also appended one item to the dropdown,
using the AppendDataBoundItems="True" property of the dropdown.
Unfortunately the item I have appended to the dropdown has become the
default value of the dropdown list which is not what I want.

Kind regards,

Steve.
Sep 13 '06 #3
I'm pretty sure you're stuck doing it in codebehind.

Karl

--
http://www.openmymind.net/
http://www.codebetter.com/
"Steve" <ba****@iranmania.comwrote in message
news:11**********************@b28g2000cwb.googlegr oups.com...
Thank you for this Karl.

Should I put this code in the page load event in page behind or can I
somehow put it as a parameter in between the dropdown tags in the page
itself.

Kind regads,

Steve
Karl Seguin [MVP] wrote:
>myDropDown.SelectedIndex =
myDropDown.Items.IndexOf(myDropDown.Items.FindByV alue("yourDefaultValue"))

you can also use FindByText which uses the text, instead of the value.

Karl

--
http://www.openmymind.net/
http://www.codebetter.com/
"Steve" <ba****@iranmania.comwrote in message
news:11**********************@b28g2000cwb.googleg roups.com...
>I have a databound dropdown in my page. I want to make one of the
values the default value. Any ideas?

Just to explain further, I have also appended one item to the dropdown,
using the AppendDataBoundItems="True" property of the dropdown.
Unfortunately the item I have appended to the dropdown has become the
default value of the dropdown list which is not what I want.

Kind regards,

Steve.

Sep 14 '06 #4

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

Similar topics

8
by: Lyn | last post by:
Hi, Can anyone tell me how the initial value displayed in Combo Box is determined when a form is opened? I am loading the dropdown from one field ("CategoryName") of a table, with "ORDER BY ". ...
0
by: Kannan.M.R | last post by:
Hi, I have a problem in assigning the selected value in the dropdown to a hidden control. It goes like this. I have a repeater control. In the repeater control’s item template, I have a...
0
by: Kannan.M.R | last post by:
hi, I have a repeater. In the item template of the repeater i have a place holder control. In the item databound event of the repeater, In a for loop, i create dropdowns and buttons in a loop and...
12
by: Randall Parker | last post by:
Using DropDownList to create select/option tags in HTML how to make the first option be a blank string? I have fields with optional values. Currently I'm populating the DropDownList by querying...
2
by: Brian Henry | last post by:
say I have a databound combo box, which allows for text entry still (DropDownStype = DropDown in this case). now, If the user doesn't enter manually an item in the data bound list, nothing...
1
by: Ami Schreiber | last post by:
I want to insert a default null ListItem with the text "choose an item ..." in my DropDownList control. I have seen similar postings here regarding this issue but all of them seem to focus around...
1
by: Ben | last post by:
I have a formview with a few dropdownlists (software version, database version, etc). When a software version is selected, the database version dropdownlist updates itself accordingly. When in...
2
by: Lair | last post by:
I am creating a page that has three to four databound dropdown lists. Each one is has different data sometimes from the same table but with a different where clause. What is the best way to...
3
by: podi | last post by:
Hi, I just wonder if there is a way to set a selected item in dropdown list which items are retreived from database without touching c# code ? I mean, i have in gridview, in edit mode one...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....

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.