![]() |
| |||||||
| Sponsored Links |
![]() | « Previous Thread | Next Thread » |
| | LinkBack | Thread Tools | Display Modes |
|
#1
| ||||
| ||||
| How does one achieve this? basically i need to add a "Select Here" to my DDL, and it must be selected. Shem |
| Sponsored Links |
|
#2
| ||||
| ||||
| Assuming you're using a datasource to bind to the DDL use something like this after you've bound the data to the ddl:- Code: ddl_id.items.insert(0, New ListItem("Please Select",""))
Last edited by richyrich; July 4th, 2008 at 04:11 AM. |
| The Following User Says Thank You to richyrich For This Useful Post: | ||
Shem (July 4th, 2008) | ||
|
#3
| ||||
| ||||
| Or alternatively if your using the DataSourceControl, set the AppendDataBoundItems to True of your DDL and then just add Code: <asp:DropDownList ID="ProjectDDL" runat="server" AutoPostBack="True" DataSourceID="ProjectDataSource" DataTextField="Name" DataValueField="Idkey" Visible="false" AppendDataBoundItems="True">
<asp:ListItem Text="Select Project" Value="0" Selected="True"></asp:ListItem>
</asp:DropDownList>
![]() Shem |
|
#4
| ||||
| ||||
| Quote:
![]() Thanks RR |
|
#5
| ||||
| ||||
| Quote:
![]() With this method I'm not sure what would happen on postback. Does it keep the Select Project item selected? |
|
#6
| ||||
| ||||
| It keeps the selected item selected, ie. doesn't just stick to "Select here". BTW: your method isn't working for me, I only tested your in conjuction to mine, basically your will also only work when AppendDataBoundItems = true ![]() Shem |
|
#7
| ||||
| ||||
| sh!t.... If you click on "Select here", it adds it to the collection, so you end up with multiple "Select Here" options |
|
#8
| ||||
| ||||
| Quote:
.aspx Code: <asp:dropdownlist id="ddl_id" runat="server" /> Code: sub Page_Load()
if not ispostback then
build_ddl_id()
end if
sub build_ddl_id()
' do all your datasource stuff first
ddl_id.datasource = your_datasource
ddl_id.databind
ddl_id.items.insert(0, New ListItem("Select Project", ""))
ddl_id.selectedvalue=""
end sub
Obviously your datasource can be a datareader or list of from a class. Hope that helps. Last edited by richyrich; July 4th, 2008 at 04:51 AM. |
|
#9
| ||||
| ||||
| ok, but i am using the datasource control, so how do i build/bind on postback? Shem |
|
#10
| ||||
| ||||
| Quote:
What happens if you remove the selected="true" from the Select Project item? |
![]() |
|
| Bookmarks |
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| [ASP.Net/VB.Net] Programmatically Select Item in ListBox or DropDownList | jmurrayhead | Code Samples | 0 | June 27th, 2008 10:05 AM |
| [ASP.Net/VB.Net] Programmatically Add Item to Validation Summary | jmurrayhead | Code Samples | 0 | March 20th, 2008 09:41 AM |