Wrox Programmer Forums
Go Back   Wrox Programmer Forums > .NET > .NET 1.0 and Visual Studio.NET > VS.NET 2002/2003
| Search | Today's Posts | Mark Forums Read
VS.NET 2002/2003 Discussions about the Visual Studio.NET programming environment, the 2002 (1.0) and 2003 (1.1). ** Please don't post code questions here ** For issues specific to a particular language in .NET, please see the other forum categories.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the VS.NET 2002/2003 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
  #1 (permalink)  
Old May 5th, 2006, 06:19 AM
Authorized User
 
Join Date: Apr 2006
Location: london, , United Kingdom.
Posts: 19
Thanks: 3
Thanked 0 Times in 0 Posts
Send a message via MSN to akshay144
Default populating a dropdown list with values from datab

I am trying to populate a dropdown list within a datagrid so that it bring up all the locations and has the location of the current employee as Selected.

The dropdown is a template column currently it shows the first location from the database.

I believe I can use the ItemDataBound property within the Datagrid but don't know how?

Any help will be highly appreciated.
  #2 (permalink)  
Old May 7th, 2006, 10:56 PM
Friend of Wrox
Points: 4,332, Level: 27
Points: 4,332, Level: 27 Points: 4,332, Level: 27 Points: 4,332, Level: 27
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Nov 2003
Location: , NJ, USA.
Posts: 1,348
Thanks: 0
Thanked 5 Times in 5 Posts
Default

Place the value you want to find in a column in the grid. Then hide that column. Then you can find that value in the ddl. You are correct in that you need to use the ItemDataBound event.

Something like:
Dim ddl As DropDownList
Dim ddlEmployees As DropDownList

ddl = CType(e.Item.FindControl("<YourDDL>"), DropDownList)
'Set the drop down list to show the value you want.
ddl.Items.FindByValue(e.Item.Cells(<cellindex).Tex t).Selected = True 'This is the hidden column.

Jim


  #3 (permalink)  
Old May 9th, 2006, 06:04 AM
Authorized User
 
Join Date: Apr 2006
Location: london, , United Kingdom.
Posts: 19
Thanks: 3
Thanked 0 Times in 0 Posts
Send a message via MSN to akshay144
Default

Thanks Jim

But i am using c# .net

can anyone help?

cheers
Akshay
  #4 (permalink)  
Old May 9th, 2006, 08:55 AM
Friend of Wrox
Points: 4,332, Level: 27
Points: 4,332, Level: 27 Points: 4,332, Level: 27 Points: 4,332, Level: 27
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Nov 2003
Location: , NJ, USA.
Posts: 1,348
Thanks: 0
Thanked 5 Times in 5 Posts
Default

use this site to convert the code:

http://www.developerfusion.co.uk/uti...btocsharp.aspx

  #5 (permalink)  
Old May 12th, 2006, 04:56 AM
Authorized User
 
Join Date: Apr 2006
Location: london, , United Kingdom.
Posts: 19
Thanks: 3
Thanked 0 Times in 0 Posts
Send a message via MSN to akshay144
Default

Jim

thanks for link to the converter..i tried it but still no luck

anyone else out there who can help?
  #6 (permalink)  
Old May 12th, 2006, 10:15 AM
Authorized User
 
Join Date: Apr 2006
Location: , , .
Posts: 60
Thanks: 0
Thanked 0 Times in 0 Posts
Default

DropDownList ddl;
ddl = (DropDownList)e.Item.FindControl("yourControlId");
ddl.Items.FindByValue(e.Item.Cells[12].Text).Selected = true;

This is the conversion of jbenson's code... 12 is your cell index for instance



Similar Threads
Thread Thread Starter Forum Replies Last Post
Populating DropDown List in DetailsView Edit Mode. kevorkian ASP.NET 2.0 Professional 2 June 9th, 2008 12:42 PM
populating a dropdown list within a datagrid in C# akshay144 General .NET 0 May 12th, 2006 04:44 AM
populating dropdown values rupen Classic ASP Basics 16 October 10th, 2005 09:48 AM
Storing multiple values from the dropdown list lily611 SQL Server 2000 0 June 21st, 2004 06:08 AM
Storing multiple values from the dropdown list lily611 ADO.NET 0 June 21st, 2004 05:21 AM





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