Trying to populate a drowonlist template field in a gridview in

I have a gird view and one my second colume is a template field.  The item template is a label but the edit is a dropdownlist.  I have used dropdownlist before in a gridview tempalte and added items to it in the aspx but this time I need to bind data from a data set into the drowdownlist.  I know how to do this but I do not know how to populate it when its a edit template.  If i just had a dropdownlist called ddl1 that was just on my web form i would do the following

ddl1.datasource = getXYZ 'getXYZ is a call to a function that returns a dataset that i want to populate the dropdownlist

ddl1.datatextfiled = "abc"

ddl1.datavaluefield ="def"



How do i access the dorpdownlist in my gridview and bind a datset to it.  If the dropdownlilst in my gridview is called ddlPayers if i code to the aspx.vb and type ddlPayers = getXYZ it says ddlPayers does not exist.

2/5/2007 5:56:45 PM 7760 articles. 0 followers. Follow

3 Replies

Similar Articles

[PageSpeed] 23

Defining your DataSource declaratively rather by through code is by far the easiest way. However, if you don't want to or can't set up your DataSource declaratively on the ASPX page, then your option is to set-up your binding within the GridView.RowDataBound event. Within this event, you'd simply retrieve the DropDownList via the GridViewRow.FindControl method and code your data bind from there. I personally try to avoid this approach and set-up my databinding declaratively through the use of an ObjectDataSource.
Thanks, Ed

Microsoft MVP - ASP/ASP.NET

2/5/2007 6:46:07 PM
Thanks for the tip I used and sqldatasource,  I have one more question how would I set the seleted value of the dropdownlist text to what ever the text is in the label for that cell. So if the label.text for the cell was "Pear" and my drowdownlist is sorted with fruits in order how to i get "Pear" to be the first thing thats show up in the dropdownlist box when the user clicks the edit button instead of "Apple" cause its sorted by fruit. 
2/5/2007 9:13:22 PM

Bind the value of the fruit to the SelectedValue attribute of the drop down list:


<asp:TemplateField HeaderText="Fruit">


<asp:Label id="FruitLabel" runat="server" Text='<%# Eval("FruitName") %>' />



<asp:DropDownList id="FruitDropDown" runat="server" DataTextField="FruitName" DataValueField="FruitID" DataSourceID="FruitDataSource" SelectedValue='<%# Bind("FruitID") %>' />





2/6/2007 12:01:05 AM

Similar Artilces:

from Visual Studio .NET to Visual studio 2005 (VB)
Good evening, i hame one quistion about diffrenece Visual studio 2005 and older version.In Visual studio .NET to work with table from data base i do next steps:1. Create new connection to data base in data explorer2. Push my table from data explorer to my form, and master automatically create two components (SqlConnection and SqlDataAdapter)3. Add to from new object - Dataset for transering data to client application (i amke a web service) and execute command from menu Data | Generate DataSet, then in Dialog box i Add this dataset to the designerThat's itThe quistion is how to do this st...

can we migrate visual studio .net 2003 project to visual 2005
Hai friends, I am doing project in ASP.NET(vb language)  I have visual studio .net 2003 installed in my pc and i am doing my project in it , because i need to use additional functionality like "AJAX" , i want to use visual studio .net 2005 or visual studio .net 2008 my project folder name is "sqls" can i install visual studio .net 2005 or visual studio .net 2008 and migrate this project folder to work in visual studio .net 2005 or visual studio .net 2008 i have uninstall visual studio .net 2003 and install visual studio .net 2005 or visual ...

Loading Visual 2003 on a pc with Visual 2005 installed
I have recently installed Visual 2005 on a pc and have been using it to create a .net 2.0 application. I also have pc running Visual Studio 2003 that I use to support a .net 1.1 application. This pc has broke. Would I be ok loading Visual Studio 2003 on the machine I have running Visual Studio 2005 so I can manage both the .net 1.1 and the .net 2.0 applications?               Thanks Danny Hmmm. Not sure if it works in that direction, but I installed VS2005 on a machine that has VS2003 already installed and they se...

Visual Studio.Net and VB.Net
Can we install VS.Net and VB.Net on the same machine and work side by. Is there any thing I need to worry about? I use VS.Net enterprise for my office work and I am planning to buy VB.Net standard for my personal use. Before I goahead and buy, I wanted to make sure that it works. Thanks for your help. Anil...

Need Visual Studio 2005 Web Part Templates for
*** UPDATE 2/12/2008:  Click here to download sharepoint VB templates ***  I installed the Microsoft supplied templates for web part development in visual studio 2005 and was pleasantly surprised to find that it did not include templates, only C# templates. Does anyone know if Microsoft has released a VB version of the templates OR Does anyone know how to convert the c# templates to VB? THANKS!Mark this post as the "Answer" if it was the answer. There's got to be someone out there developing...

Visual Studio 2005 Edition Released! Is it the same as Visual Studio.Net 2005 ?
Edited by XIIIVisual Studio 2005 Edition Released! Is it the same as Visual Studio.Net 2005 ? Yes. ".NET" part is not actually/officially part of the Visual Studio 2005 name.-- Mike PopeASP.NET User EducationThis posting is provided "AS IS" with no warranties, and confers no rights. Is it Visual Studio .NET 2003 update version? Does Microsoft change its name? I'm not sure I understand your question exactly -- I'm a little thrown by the word "update." Visual Studio 2005 is the new/current version, released on Monday. This product never officially had the word ".NET" in its nam...

Visual Studio .NET vs Visual Studio .NET 2002 or 2003?
As an admin, I'm working to determing what systems I need to update with the update on MS08-017, particularly with respect to Visual Studio .NET 2002 and 2003. I've got quite a few systems that appear to have Visual Studio .NET, no 2002 or 2003 mentioned when I view what's there in Add/Remove Programs. Is there a definitive way to determine if I have a 2002 or 2003 version?   sandy_wood:Is there a definitive way to determine if I have a 2002 or 2003 version? In add/remove programs it would indicate it VS2003 as Visual Studio 2003. Alternatively launch the applicatio...

visual 2003 conflict visual 2003
hello does visual 2003 makes conflict with visual 2003? thank you for the help and for the support No, the RTM version (I think this is true also for Beta 2), will work on the same machine without any problems./Fredrik Normén - fredrikn @ twitterMicrosoft MVP, MCSD, MCAD, MCTASPInsidersMy Blog i am shure 2003 doenst conflict with 2003 ;-)-Hannes the subject says "visual 2003 conflict visual 2003". is he talking about 2003 and 2005 ? pradeep_TP I think he is talking abo...

Converting windows application using web service from Visual 2003 to Visual 2005
Hello, everyone! I have a solution which contains a windows project,a web service project and several other library projects. These projects were coded under visual 2003. Now I need to converted them to use Visual 2005. Does any one know any article providing step-by-step guide  to converting WINDOWS APPLICATION with web service? I can find one under MSDN for converting web project.  But I guess I am a little confused if mine should follow this article since I am using web service in my windows application? Thanks a lot in advance.  ...

Visual Studio.NET VB.NET Edition for DNN?
I have been plugging along using the Handcoded method for Module Development up to this point and although I have been successful I'd like to possibly make the jump up to Visual Studio. I was looking at Microsot's Website and there is a VB.Net only version that lists for only $109 vs. the $1000+ for the full fleged Professional Edition. Is it possible to adequately develop for the DNN platform using this trimmed down (VB.NET only) version of Visual Studio 2003? The VB.NET 2003 package is more than adequate for DDN moodules or full-blown ASP.NET applications. Highly recommended... mi...

Visual Basic.NET or Visual Studio.NET?
OK, this has probably been asked before... I'm a student looking to cut my costs, and I can do this by just purchasing Visual Basic.NET as opposed to the fully-fledged Visual Studio.NET application. Of course, I'll only be able to program in VB, but that's fine with me. I wanted to know if all of the ASP.NET specific options are available, such as using a WYSIWYG editor? I'd also like to know if VB.NET has IntelliSense, or that's a specific option only available to Visual Studio.NET users. Thanks in advance. I'd have to believe that VB.Net has intellisense. What is the price d...

Visual Studio .Net? Visual Basic .Net?
Okay, I admit it -- I know nothing about .Net. I'm a Visual Basic and ASP developer. DotNetNuke is my first tentative step into the whole ".Net Thing", and I'm looking for some advice... What do I really need to be able to make some modifications, or new modules for DotNetNuke? Do I need the full, THOUSAND DOLLAR Visual Studio .Net 2003 package, or can I get away with the HUNDRED DOLLAR Visual Basic .Net Standard package?Chameleon Systems, Inc. You can use webmatrix, available here for free. One of the drawbacks of webmatrix however is that it does not support code-be...

Can I Have Visual Studio.NET and Visual Studio 2005 together?
Hi everyone. Can I have Visual Studio.NET and Visual Studio 2005 installed in the same machine? I want to install Studio 2005 but I do not want to uninstall Studio.NET yet. Thanks!C# I am running VS 2003 and VS 2005 together with no problems.Martin Lawrence, MCSE, CNE, A+ Recut Technologies Ltd. Yes, they can be installed side-by-side. I have it installed side-by-side on my computer and it works perfectly without any conflicts. I even think there is a Version Selector (not something you have to install as it is installed by default) which will make sure your pro...

VB.NET vs. C#.NET Behavior of Visual Studio
I'm transitioning from coding in VB to coding in C#. Maybe I have something set wrong, but a behavioral difference is driving me bananas. When I edit a VB source file, the two drop-downs at the top of the edit view are Class Name and Method Name, and it makes it easy to add a new event handler for any of the controls on the page. Choose which one on the left, pick your event on the right, and VS inserts an empty, properly formatted subroutine. In C# mode, however, those two drop-downs are labeled Types and Members, and there doesn't appear to be a way to tell it to create the empty framew...

Web resources about - Trying to populate a drowonlist template field in a gridview in -

Resources last updated: 12/20/2015 8:58:04 AM