Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / ASP.NET / General / July 2007

Tip: Looking for answers? Try searching our database.

ObjectDataSource and DropDownList

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Bill Gower - 30 Jul 2007 23:06 GMT
I have a asp.net page that has a DDL tied to a ObjectDataSource.  I want the
DDL to display a blank in the list when the page is first displayed and let
the user select the entry they want.  I have tried

CategoryList.SelectedIndex = -1

and

CategoryList.SelectedValue = ""

Neither clears out the list.  How do I display a blank?

Bill
Jesse Houwing - 30 Jul 2007 23:23 GMT
* Bill Gower wrote, On 31-7-2007 0:06:
> I have a asp.net page that has a DDL tied to a ObjectDataSource.  I want the
> DDL to display a blank in the list when the page is first displayed and let
[quoted text clipped - 7 lines]
>
> Neither clears out the list.  How do I display a blank?

In the designer, add a blank item to the items list of the dropdown. Set
the text to an empty string and the value to -1. Then look for a
property that is called something like "AppendWhenDataBinding"... (The
exact phrasing eludes me at this moment...) and set it true.

Now that you have your blank element both your old statements should be
able to set it to the empty line by default.

Jesse
Bill Gower - 31 Jul 2007 00:17 GMT
Do you mean in the Page Load event?

>* Bill Gower wrote, On 31-7-2007 0:06:
>> I have a asp.net page that has a DDL tied to a ObjectDataSource.  I want
[quoted text clipped - 18 lines]
>
> Jesse
Jesse Houwing - 31 Jul 2007 01:45 GMT
* Bill Gower wrote, On 31-7-2007 1:17:
> Do you mean in the Page Load event?

No. Open the page with the dropdown in the designer. Look in the
properties. There's an items property. Open the items property with the
little [...] buton and click the add button. Give the thing a valeu of
-1 and clear the text that's automatically put in there. Close the
window and look for the AppendDataboundItems and set it to true.

Now if you load the page, it has an empty item on top. There's no need
to set it to the empty value, because the dropdown will always default
to it's top-most item unless specified otherwise.

Jesse

>> * Bill Gower wrote, On 31-7-2007 0:06:
>>> I have a asp.net page that has a DDL tied to a ObjectDataSource.  I want
[quoted text clipped - 17 lines]
>>
>> Jesse
Brandon Gano - 31 Jul 2007 02:12 GMT
If you can't use the designer (either because you are using nested master
pages or because you just can't stomach the output), you can do it in the
aspx as follows:

<asp:SqlDataSource ID="MyDataSource" ... />
<asp:DropDownList DataSourceID="MyDataSource" AppendDataBoundItems="true">
  <asp:ListItem Value="" Text="" />
</asp:DropDownList>

>* Bill Gower wrote, On 31-7-2007 1:17:
>> Do you mean in the Page Load event?
[quoted text clipped - 32 lines]
>>>
>>> Jesse
Bill Gower - 31 Jul 2007 03:51 GMT
Thanks that really helped.  Just one problem to solve, even though I have
deleted the Text value in the Items collection field, it still displays -1
in the drop down and I did check, I am displaying the proper field in the
list.

Bill

>* Bill Gower wrote, On 31-7-2007 1:17:
>> Do you mean in the Page Load event?
[quoted text clipped - 32 lines]
>>>
>>> Jesse
Brandon Gano - 31 Jul 2007 04:40 GMT
Try to manually add Text="" in the aspx. Clearing the value in the
properties window probably removes the attribute from the control, which
would result in the value being shown by default (-1 in this case). Another
solution might be to use an empty value as well--unless your code
specifically requires -1 for unselected ddl values.

> Thanks that really helped.  Just one problem to solve, even though I have
> deleted the Text value in the Items collection field, it still displays -1
[quoted text clipped - 39 lines]
>>>>
>>>> Jesse
Jesse Houwing - 31 Jul 2007 12:32 GMT
* Bill Gower wrote, On 31-7-2007 4:51:
> Thanks that really helped.  Just one problem to solve, even though I have
> deleted the Text value in the Items collection field, it still displays -1
> in the drop down and I did check, I am displaying the proper field in the
> list.

I the past I've used &nbsp; as the text field. Not completely empty, but
it does the trick from a users perspective.

Jesse

>> * Bill Gower wrote, On 31-7-2007 1:17:
>>> Do you mean in the Page Load event?
[quoted text clipped - 31 lines]
>>>>
>>>> Jesse

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.