Wrox Programmer Forums
|
BOOK: ASP.NET 2.0 Website Programming Problem Design Solution ISBN: 978-0-7645-8464-0
This is the forum to discuss the Wrox book ASP.NET 2.0 Website Programming: Problem - Design - Solution by Marco Bellinaso; ISBN: 9780764584640
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: ASP.NET 2.0 Website Programming Problem Design Solution ISBN: 978-0-7645-8464-0 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old January 3rd, 2008, 04:27 PM
Registered User
 
Join Date: Mar 2007
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Default Bind DropDownList with null values

I have a bound dropdownlist that will have null values for the company id. This causes problems with my dropdownlist however. I have tried several work arounds but none seem to fix my problem.

Here is my current code that works as long as I have a company id.
         <asp:TemplateField HeaderText="Bill To" SortExpression="CompanyID">
            <ItemTemplate>
               <asp:Label ID="lblCompany" runat="server" Text='<%# Eval("CompanyName") %>'></asp:Label>
            </ItemTemplate>
            <EditItemTemplate>
               <asp:DropDownList ID="ddlCompany" runat="server" DataSourceID="objAllCompanys"
                  DataTextField="CompanyName" DataValueField="ID" SelectedValue='<%# Bind("CompanyID") %>' Width="300px" />
               <asp:ObjectDataSource ID="objAllCompanys" runat="server" SelectMethod="GetCompany"
                  TypeName="MB.DinoCorp.BLL.Shop.Company"></asp:ObjectDataSource>
            </EditItemTemplate>
         </asp:TemplateField>

The first workaround I tried was to add a null listitem as follows.
         <asp:TemplateField HeaderText="Bill To" SortExpression="CompanyID">
            <ItemTemplate>
               <asp:Label ID="lblCompany" runat="server" Text='<%# Eval("CompanyName") %>'></asp:Label>
            </ItemTemplate>
            <EditItemTemplate>
               <asp:DropDownList ID="ddlCompany" runat="server" DataSourceID="objAllCompanys"
                  DataTextField="CompanyName" DataValueField="ID" SelectedValue='<%# Bind("CompanyID") %>' Width="300px">
                  <asp:ListItem Value="" Text="Select Value"></asp:ListItem>
               </asp:DropDownList> />
               <asp:ObjectDataSource ID="objAllCompanys" runat="server" SelectMethod="GetCompany"
                  TypeName="MB.DinoCorp.BLL.Shop.Company"></asp:ObjectDataSource>
            </EditItemTemplate>
         </asp:TemplateField>


Thanks for reading.


 
Old January 5th, 2008, 01:45 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 917
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I don't understand how you could bill to a null company? Is there any reason why GetCompany must return null values? Can't you filter them out in the SQL?

Eric

 
Old January 8th, 2008, 03:05 PM
Registered User
 
Join Date: Mar 2007
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Default

It is not about billing to a null Company. We are more or less in the early stages of establishing a project and determining if we will get the bid. There are a couple of reasons why the Company may be null at this point, first the Company may not be set up in the system yet as we may only be in bidding phase of a project or it is an individual and will be a bill direct. We don't set up every company we do a bid for in our system only those that get signed to a contact.

Thanks,
J

 
Old January 9th, 2008, 02:19 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 917
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Can you just create a new ID that means "N/A"? Stick a special number into those SQL records so it will come down to the page. If anyone tries to use that ID in actual processing you could give an error.

Maybe someone else has some better ideas?

Eric






Similar Threads
Thread Thread Starter Forum Replies Last Post
Cannot bind from DropDownList to DetailsView kiekar ASP.NET 2.0 Basics 0 February 19th, 2008 09:26 PM
How ti bind data in dropdownlist? aaronabdiel ASP.NET 2.0 Basics 1 February 11th, 2008 09:28 PM
how to handle null values imaginevictor ASP.NET 1.x and 2.0 Application Design 1 March 20th, 2007 01:52 AM
Null values jmcgranahan BOOK: Access 2003 VBA Programmer's Reference 0 August 29th, 2006 02:25 PM
CheckBoxList and Null Values steve35719 ASP.NET 2.0 Basics 1 April 21st, 2006 09:42 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.