Hi,
I've just add a couple of dropdowns to my ASP form, set up a
sqldatasource and bound to the dropdown and it all works great.
I want the first item of the dropdown to be blank soa fter reading a few
articles the DropDownList1.S electedIndex = -1 seems the way to go.
I've tried setting this oin the asp page and on a page load event in the
vb behind but I still cant get a blank dropdown
Any pointers gratefully received I'm sure I'm missing something simple
Regards
Jim 8 4558
No, you actually need to add an empty item.
You can do it in the database, in the datasource after filling it up from
the database or in the control after databinding it to the datasource.
If you databind to a SqlDataSource, it is easier to add an item to the
database. Otherwise you will need to understand the stages and aspects of
databinding, which is what the SqlDataSource is intended to save you from.
--
Eliyahu Goldin,
Software Developer & Consultant
Microsoft MVP [ASP.NET] http://msmvps.com/blogs/egoldin
"Jim Florence" <fl************ @hotmail.comwro te in message
news:45******** **************@ ptn-nntp-reader02.plus.n et...
Hi,
I've just add a couple of dropdowns to my ASP form, set up a
sqldatasource and bound to the dropdown and it all works great.
I want the first item of the dropdown to be blank soa fter reading a few
articles the DropDownList1.S electedIndex = -1 seems the way to go.
I've tried setting this oin the asp page and on a page load event in the
vb behind but I still cant get a blank dropdown
Any pointers gratefully received I'm sure I'm missing something simple
Regards
Jim
"Eliyahu Goldin" <RE************ **************@ mMvVpPsS.orgwro te in
message news:O3******** ******@TK2MSFTN GP03.phx.gbl...
No, you actually need to add an empty item.
You can do it in the database, in the datasource after filling it up from
the database or in the control after databinding it to the datasource.
If you databind to a SqlDataSource, it is easier to add an item to the
database. Otherwise you will need to understand the stages and aspects of
databinding, which is what the SqlDataSource is intended to save you from.
That is precisely why I hate, loathe and abominate all these DataSource
controls in v2 - we're half-way back to FrontPage here...!
"Jim Florence" <fl************ @hotmail.comwro te in message
news:45******** **************@ ptn-nntp-reader02.plus.n et...
Jim,
I've just add a couple of dropdowns to my ASP form, set up a sqldatasource
and bound to the dropdown and it all works great.
I want the first item of the dropdown to be blank soa fter reading a few
articles the DropDownList1.S electedIndex = -1 seems the way to go.
I've tried setting this oin the asp page and on a page load event in the
vb behind but I still cant get a blank dropdown
Any pointers gratefully received I'm sure I'm missing something simple
It's not so much that you're missing something simple, it's more the fact
that you're using the SqlDataSource control... This is supposed to make
database integration "simpler", which it does, but in doing so loses a whole
set of functionality which is possible if you don't use it...
If you were to bind your DropDownList programatically rather than
declaratively, you could accomplish what you require with just one extra
line of code e,g,
MyDropDownList. DataSource = <fetch dataset from database>;
MyDropDownList. DataValueField = <field from dataset>;
MyDropDownList. DataTextField = <field from dataset>;
MyDropDownList. DataBind();
That takes care of the databinding.
Now, to add a blank option at the top of the list, all you need is:
MyDropDownList. Items.Insert(0, new ListItem("", ""));
You don't have to hate them. You can quietly go back to the old good
DataSource databinding and leave xxxDataSource controls for the others who
are (or think they are) happy with them :)
--
Eliyahu Goldin,
Software Developer & Consultant
Microsoft MVP [ASP.NET] http://msmvps.com/blogs/egoldin
"Mark Rae" <ma**@markNOSPA Mrae.comwrote in message
news:OC******** ********@TK2MSF TNGP03.phx.gbl. ..
"Eliyahu Goldin" <RE************ **************@ mMvVpPsS.orgwro te in
message news:O3******** ******@TK2MSFTN GP03.phx.gbl...
No, you actually need to add an empty item.
You can do it in the database, in the datasource after filling it up
from
the database or in the control after databinding it to the datasource.
If you databind to a SqlDataSource, it is easier to add an item to the
database. Otherwise you will need to understand the stages and aspects
of
databinding, which is what the SqlDataSource is intended to save you
from.
>
That is precisely why I hate, loathe and abominate all these DataSource
controls in v2 - we're half-way back to FrontPage here...!
"Milosz Skalecki [MCAD]" <mi*****@REMOVE ITwp.plwrote in message
news:00******** *************** ***********@mic rosoft.com...
You don't need to code it yourself, AppendDataBound Items is invented
exactly
for this scenario:
<asp:DropDownLi st runat="server" AppendDataBound Items="true" ID="ddl"
DataSourceID="d s">
<asp:ListItem Text="Please select..." Value=""/>
</asp:DropDowList >
Thanks for that - I didn't know that was possible...
I managed to fix it by scrapping my initial idea and adding a line in
the code behind to add a blank and set the appenddatabound items to true
on the dropdown list.
The problem I'm having now is that I can't get the SelectedIndexCh anged
procedure to see the DropDownList1.S electedItem.Tex t, it returns a blank
and it's definitely being selected.
The plot thickens
Jim Florence
Jim Florence wrote:
Hi,
I've just add a couple of dropdowns to my ASP form, set up a
sqldatasource and bound to the dropdown and it all works great.
I want the first item of the dropdown to be blank soa fter reading a few
articles the DropDownList1.S electedIndex = -1 seems the way to go.
I've tried setting this oin the asp page and on a page load event in the
vb behind but I still cant get a blank dropdown
Any pointers gratefully received I'm sure I'm missing something simple
Regards
Jim
"Jim Florence" <fl************ @hotmail.comwro te in message
news:45******** ******@hotmail. com...
>I managed to fix it by scrapping my initial idea and adding a line in the code behind to add a blank and set the appenddatabound items to true on the dropdown list.
Sounds like you're mixing the declarative method and programmatical method
of binding your data...
The problem I'm having now is that I can't get the SelectedIndexCh anged
procedure to see the DropDownList1.S electedItem.Tex t, it returns a blank
and it's definitely being selected.
Have you tried following Milosz' advice and adding the "default" blank
option inside the <asp:DropDownLi sttag...?
I managed to fix it by scrapping my initial idea and adding a line in
the code behind to add a blank and set the appenddatabound items to true
on the dropdown list.
The problem I'm having now is that I can't get the SelectedIndexCh anged
procedure to see the DropDownList1.S electedItem.Tex t, it returns a blank
and it's definitely being selected.
The plot thickens
Jim Florence
Jim Florence wrote:
Hi,
I've just add a couple of dropdowns to my ASP form, set up a
sqldatasource and bound to the dropdown and it all works great.
I want the first item of the dropdown to be blank soa fter reading a few
articles the DropDownList1.S electedIndex = -1 seems the way to go.
I've tried setting this oin the asp page and on a page load event in the
vb behind but I still cant get a blank dropdown
Any pointers gratefully received I'm sure I'm missing something simple
Regards
Jim
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: % =joe % |
last post by:
I cannot get this code to work. Very simple...I have three list
menus. I want to do a check before the form submits to make sure that
the value of the 3 fields is equal to 12.
Here's my code...
<script language="javascript">
<!--
function addListValues() {
|
by: Emil |
last post by:
Can somebody tell me what would be the syntax for having an if statement and
setting the selected index of a radiobuttonlist?
This is my first project using ASP.net and I use C#.
I have a repeater with like a table layout and in the last column I want to
have three radio buttons (for each row in repeater). The value of the radio
button should be calculated from a value from the dataset.
How can I do that? When I try to use a variable...
|
by: MrSmoofy |
last post by:
Ok I'll start out with I found:
http://support.microsoft.com/kb/327244/
BUG: ComboBox Does Not Clear When You Set SelectedIndex to -1
Ok so in HTML you can have:
<select id="MyList">
<option value="1">1
<option value="2">2
|
by: Eric A. Johnson |
last post by:
Hi Everyone,
I am at my wit's end here. I have a combobox (combyQueryTitle) that I
need to use in order to select a query for my database project. Therefore,
I am using the comboQueryTitle_SelectedIndexChanged handler to, when a new
selection is made, update the query and refresh the display. The only
problem is that the program seems to inexplicably start with the
..selectedindex property at -1! This makes no sense to me. ...
|
by: Badass Scotsman |
last post by:
Hello,
I have some "runat server" form drop downs on the page, for example:
<asp:DropDownList ID="TypeOfParrot" Runat="server" name="TypeOfParrot"
class="textbox">
<asp:ListItem Value="">Please Select</asp:ListItem>
<asp:ListItem Value="Cockatoo">Cockatoo</asp:ListItem>
<asp:ListItem Value="MaCaw">MaCaw</asp:ListItem>
<asp:ListItem Value="African Grey">African Grey</asp:ListItem>
| |
by: Alec MacLean |
last post by:
Hi,
I have a couple of win forms where I am editing values that are stored in a
SQL database.
I'm using the listbox control to hold the data object each form interacts
with. Each object is defined by my own classes.
On the first form, I use an approach to reduce the number of database calls.
This essentially consists of :
|
by: bryant |
last post by:
Hi all.
I am new to ASP and working in Expression Web. The following query
displays the information I need in the gridview for a single record.
SELECT "OE_HDR"."ORD_NO", "OE_HDR"."CUST_NAM", "OE_HDR"."SLS_MAN_NO",
"OE_HDR"."SLS_MAN_INITIALS", "OE_HDR"."ORD_DAT", "OE_HDR"."SHIP_DAT"
FROM "OE_HDR" WHERE ("OE_HDR"."ORD_NO"='174310')
I also have DropDownList1 working properly. For the WHERE portion of
|
by: Ben |
last post by:
Hi,
i dynamically feed a dropdownlist which value from 1 to 20. That
dropdownlist is bound to field 'wa' (type nvarchar(4)) in 'mytable'. There
are 4 records and the values of field 'wa' are: 2 3 1 4. All those values
are contained in the list of items of the DD.
In normal mode, the field 'wa' appears for each record with the right value.
When i click on the Edit button, i get this error:
"DropDownList1' has a SelectedValue which is...
|
by: xtremebass |
last post by:
Hello Bytes,
i have a calender program which is created by using Javascript. when i execute that program using Internet Explorer,it works properly but when i tried in Mozilla firefox it didnt worked.
Dates of particular year,month not displayed in that calender grids. i have collected that coding from online free resources.
Here i have attached code for your reference. please do suggest me how do i display the calender date in grids in...
|
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...
|
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
| |
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
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...
|
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...
|
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...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
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...
| |