473,472 Members | 2,191 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

hard code data bind

Hi all,

firstly this is a web apps project.

Right i had a dropdown list which was populated by a db table which was
databound using a sql datasource.

however when adding validation controls the dropdownlist was failing as
an item was already selected. I need a default value in there "please
select one" to appear when the page is loaded or postback occurs. This
dropdownlist item cannot appear in the db but must appear in the list
and appear first before the other items populated by the db.

I have deleted the databond between sql datasource and the dropdownlist
and have written a select statement to grab the categories. i need to
add the "please select one" item before the db is called and then loop
untill all records from the db have been populated into the drop down
list.

all i have so far is below:

Protected Sub DropDownList1_DataBinding(ByVal sender As Object,
ByVal e As System.EventArgs) Handles DropDownList1.DataBinding

Dim SelectCategory As New SqlCommand
Dim ConCategory As New
SqlConnection(dataCategories.ConnectionString)
Dim Param As New SqlParameter("@CategoryID",
Data.SqlDbType.Int)

DropDownList1.Items.Add("Please Select One")

SelectCategory.CommandText = "SELECT category FROM [faq
category] WHERE categoryID = @categoryid"
ConCategory.Open()

Dim reader As SqlDataReader = SelectCategory.ExecuteReader
While reader.Read
DropDownList1.SelectedItem.Value = reader(0)
End While
ConCategory.Close()

End Sub

probably going the wrong way with but thats why i need your help.

many thanks

simon

Oct 20 '06 #1
2 3006
Have you tried setting the text of the combobox to "Select One" then it
should show as default.

--
Thiele Enterprises - The Power Is In Your Hands Now!

--
"si_owen" <s.****@sstaffs.gov.ukwrote in message
news:11**********************@h48g2000cwc.googlegr oups.com...
Hi all,

firstly this is a web apps project.

Right i had a dropdown list which was populated by a db table which was
databound using a sql datasource.

however when adding validation controls the dropdownlist was failing as
an item was already selected. I need a default value in there "please
select one" to appear when the page is loaded or postback occurs. This
dropdownlist item cannot appear in the db but must appear in the list
and appear first before the other items populated by the db.

I have deleted the databond between sql datasource and the dropdownlist
and have written a select statement to grab the categories. i need to
add the "please select one" item before the db is called and then loop
untill all records from the db have been populated into the drop down
list.

all i have so far is below:

Protected Sub DropDownList1_DataBinding(ByVal sender As Object,
ByVal e As System.EventArgs) Handles DropDownList1.DataBinding

Dim SelectCategory As New SqlCommand
Dim ConCategory As New
SqlConnection(dataCategories.ConnectionString)
Dim Param As New SqlParameter("@CategoryID",
Data.SqlDbType.Int)

DropDownList1.Items.Add("Please Select One")

SelectCategory.CommandText = "SELECT category FROM [faq
category] WHERE categoryID = @categoryid"
ConCategory.Open()

Dim reader As SqlDataReader = SelectCategory.ExecuteReader
While reader.Read
DropDownList1.SelectedItem.Value = reader(0)
End While
ConCategory.Close()

End Sub

probably going the wrong way with but thats why i need your help.

many thanks

simon
Oct 20 '06 #2
yes that was the first thing i tried, but the drag and drop data bind
over rides cjanging the text property in the properties.

Oct 23 '06 #3

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

Similar topics

9
by: Philip D Heady | last post by:
Ok, as some of you may know I'm an Oracle newbie w/ PHP. I'd rather use MySQL but at the office here we use Oracle and boy do I have alot to learn. I'm starting to hate it after using MySQL!! ...
33
by: n00m | last post by:
import socket, thread host, port = '192.168.0.3', 1434 s1 = socket.socket(socket.AF_INET, socket.SOCK_STREAM) s2 = socket.socket(socket.AF_INET, socket.SOCK_STREAM) s2.connect((host, 1433))...
6
by: allenj | last post by:
DB21085I Instance "md" uses "32" bits and DB2 code release "SQL08012" with level identifier "02030106". Informational tokens are "DB2 v8.1.0.16", "s030508", "MI00048", and FixPak "2". Product is...
4
by: John Boy | last post by:
Hi, Can anyone help. This is really doing my nut in. 3 years ASP exp. and now doing .DOT which is a step in the wrong direction. Basically I am left with the code of a guy who has left. When I...
21
by: Simon Verona | last post by:
Hope somebody can help! I want to automatically be able to add code to the initialize routine on a Windows form when I add a custom control that I've written to a form. Specifically, I'm trying...
5
by: denvercr | last post by:
hi guys just want to get input from you on how can i bind data to a dropdownlist manually or in hard code?.. How can I use ObjectDataSource for this binding? or is there any other way?.. ...
5
by: Jens | last post by:
Hello, I have been looking for some C-code which listens on a user-defined port for incoming data traffic. When data is received, the data is written to a file. I found some C-code (server)...
9
by: Sayudh27 | last post by:
Hi all, I am a relatively new programmer in C++...I need to write a code that performs multicasting as well as returns the data-packets in a decompressed form.Data-receipt seems to work...
6
by: Tomasz J | last post by:
Hello developers, I bind my TextBox control specyfying a format stored in my application global ApplicationContext object - it has a static string CurrencyFormat property. The problem - this...
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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...
1
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...
0
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,...
1
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...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.