Wrox Programmer Forums
|
ASP.NET 2.0 Basics If you are new to ASP or ASP.NET programming with version 2.0, this is the forum to begin asking questions. Please also see the Visual Web Developer 2005 forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 2.0 Basics 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 June 9th, 2006, 01:46 PM
Registered User
 
Join Date: Jun 2006
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default Drop Down List Control Issue

Hey all,

I'm creating a web app to tracking computers and assigned technicians. I use a database with 2 tables (Server and Tech). Server has a primary key of server_id and Tech has a primary key of user_id. I've created the database with constrains that a Tech can have many Servers but a Server doesn't require a Tech.

Now, onto the problem:

I've gotten to the point of creating the edit page to this app. On the edit page I have a Form View pulling in data from a SQL database table using an ObjectDataSource. Everything populated fine when I pull up a server to view/edit. I decided to complicate things by adding a DDL to show the actual tech name (full_name) instead of the foreign key (user_id). I did this with a SQLDataSource and displaying the user name instead of the user_id field. This works great if the server has a tech associated, but when there is no Tech associated, I get the following error:

'user_idDDL' has a SelectedValue which is invalid because it does not exist in the list of items.
Parameter name: value

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.ArgumentOutOfRangeException: 'user_idDDL' has a SelectedValue which is invalid because it does not exist in the list of items.
Parameter name: value


I figured I could get around this issue using some code within my DDL tag. This is what I've got so far but I can't get the syntax correct:

<asp:DropDownList ID="user_idDDL" DataSourceID="SqlDataSource1" runat="server" DataTextField="full_name" DataValueField="user_id" SelectedValue='<%# if (user_id !='') { Bind("user_id") } %>' AppendDataBoundItems="true"> <asp:ListItem Value="0"> Select a Tech </asp:ListItem> </asp:DropDownList>

Basically, I want to say:

If user_id !='' { BIND("user_id") } else { POPULATE LIST WITH ALL TECHS & SELECT 'Select a Tech' }

How would I format that within my DDL tag. Any help would be greatly appreciated.

Thanks,
Roger


--------------------------------------------------------------------------------
Thanks,

Roger A






Similar Threads
Thread Thread Starter Forum Replies Last Post
Drop Down Issue SKhna ASP.NET 2.0 Basics 1 March 19th, 2008 06:29 AM
drop down list values based on another drop down noor ASP.NET 1.0 and 1.1 Basics 3 July 5th, 2005 09:57 AM
Drop down issue(s) Annoyamouse Pro PHP 0 March 31st, 2005 06:00 PM
Drop Down List Control RobEdyvean General .NET 8 May 6th, 2004 09:10 AM





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