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
5 7899
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 - CType(Sender, DropDownList).Items.Insert(0, "")
C# - ((DropDownList)Sender).Items.Insert(0, "");
You might want to verify the C#...I don't recall if my case selection is correct.
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
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. - DropDownList1.DataBind()
-
DropDownList1.Items.Insert(0, "Select...")
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
Thank you so much for all your help.
Yes, after changing Add to Insert, I had my expected result.
Thank you again.
ellen89
Sign in to post your reply or Sign up for a free account.
Similar topics
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...
|
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,...
|
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";...
|
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...
|
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
|
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...
|
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...
|
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...
|
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...
|
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...
|
by: ryjfgjl |
last post by:
ExcelToDatabase: batch import excel into database automatically...
|
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...
|
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...
|
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)...
|
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...
|
by: Defcon1945 |
last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
|
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
|
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...
| |