473,320 Members | 1,993 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.

How to let the first Row in DropDown list being blank?(using sproc)

14
Hi All,

I have a dropdown list control, and its items are loaded from database during the page_load.

say, the values in the db table are not allowed to be NULL.

I want to have the first row in dropdown list being blank. It means the user has to click the dropdown arrow to see the items.

Thank you for your help in advance.

ellen89
Mar 16 '08 #1
5 7899
balabaster
797 Expert 512MB
Hi All,

I have a dropdown list control, and its items are loaded from database during the page_load.

say, the values in the db table are not allowed to be NULL.

I want to have the first row in dropdown list being blank. It means the user has to click the dropdown arrow to see the items.

Thank you for your help in advance.

ellen89
In the databind event for the dropdownlist, do:

VB
Expand|Select|Wrap|Line Numbers
  1. CType(Sender, DropDownList).Items.Insert(0, "")
C#
Expand|Select|Wrap|Line Numbers
  1. ((DropDownList)Sender).Items.Insert(0, "");
You might want to verify the C#...I don't recall if my case selection is correct.
Mar 16 '08 #2
ellen89
14
Thank you for your reply.

I did following:

DropDownList1.DataBind();
DropDownList1.Items.Add(new ListItem("", ""));

it inserted the Blank Line at the Bottom of my list. Then I tried

DropDownList1.Items.Add(new ListItem("", ""));
DropDownList1.DataBind();

Now this time nothing happend.

Wondering to where to insert DropDownList1.Items.Add(new ListItem("", ""))?

Thanks,
ellen89
Mar 16 '08 #3
balabaster
797 Expert 512MB
Thank you for your reply.

I did following:

DropDownList1.DataBind();
DropDownList1.Items.Add(new ListItem("", ""));

it inserted the Blank Line at the Bottom of my list. Then I tried

DropDownList1.Items.Add(new ListItem("", ""));
DropDownList1.DataBind();

Now this time nothing happend.

Wondering to where to insert DropDownList1.Items.Add(new ListItem("", ""))?

Thanks,
ellen89
That's because a). "Add" adds the new item at the end...and you want it inserted at the beginning and b). When you databind the control, it erases the previous contents, so having added the new entry, the control is then immediately cleared and populated with new data.
Expand|Select|Wrap|Line Numbers
  1. DropDownList1.DataBind()
  2. DropDownList1.Items.Insert(0, "Select...")
Mar 17 '08 #4
kunal pawar
297 100+
Using Add method u can add listitem at the last position, but using insert method u can insert list item at any position. and another thing after add/insert not need to call bind method
Mar 17 '08 #5
ellen89
14
Thank you so much for all your help.

Yes, after changing Add to Insert, I had my expected result.

Thank you again.

ellen89
Mar 18 '08 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Joseph Barron | last post by:
Here is a SIMPLE problem that I'm trying to solve. It works in Netscape 6.2, but IE6 gives ""No such interface supported." Below are page1.htm and page2.htm . In page1.htm, there are two...
3
by: Big Dave | last post by:
I know it's been asked a million times before, but I still can't seem to find an answer that works. I've got a dropdown list in the footer template of a datagrid. The dropdown list databinds,...
3
by: JIM.H. | last post by:
Hello, I am suing SELECT * from MyTable in a stored procedure and populate dropdown list. By using followings: ddlSP.DataSource = DS; ddlSP.DataTextField = "PName"; ddlSP.DataValueField = "PID";...
3
by: er1 | last post by:
Hi all, I have created a double dropdown list. Based on the first list selection, second list populates (this works fine). I have a submit button, which when clicked should run a select query...
1
by: tech.fors | last post by:
Hi , How to make multiple select in dropdown list box using asp and access can anyone help me regarding this. thanking u in advance, Regards, tech.fors
4
by: mathewgk80 | last post by:
Hi everybody, I am having a drop down list with items 1,2,3.. and another dropdown list with items apple,orange and lemon.. If i select item 2 in the first dropdown list i need to get orange as...
5
by: abhi3211 | last post by:
i am using java inside java script page. in that page i want to use two dropdown list. in first dropdown list i am getting data from ms-access database. in second dropdown list i want to get data...
9
by: nixan | last post by:
hi every one im using php for developing a project. now im having big problem, i have three drop down lists(lets say DD1,DD2,DD3) they will show item from database. for example DD1 have(it will...
0
by: progman417 | last post by:
I have a gridview with a dropdown list in an EditItemTemplate. I haven't set a width for the columns, so that they dynamically size according to the data displayed. When it goes into edit...
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: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
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: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.