473,385 Members | 1,753 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Populating DropDownList in GridView

Hi again,

Okay, I decided the GridView is the way to go to solve my problem. But now I've got another problem.

I've found plenty of examples about how to add a DropDownList item to the grid view, how to bind it and how to add the selection items to the list. My problem is that in all the examples I can find all show how to add the selection items from a database only. I don't always want to do that. Sometimes I want to add just from a predefined list of values.

For example:
Expand|Select|Wrap|Line Numbers
  1.                 <asp:TemplateField HeaderText="Color">
  2.                     <ItemTemplate>
  3.                         <asp:DropDownList DataSource="<%# GetColors() %> 
  4.                         DataTextField="Color" DataValueField="Color" 
  5.                         ID="ddlColor" runat="server">
  6.                         </asp:DropDownList>
  7.                     </ItemTemplate>
  8.                 </asp:TemplateField>
  9.  
(I haven't done the binding step yet). In the examples I've found, the GetColors() method selects from a database. Instead, I want to simply have the selections 'RED', 'BLUE', 'GREEN' only. Whatever the user enters will eventually get stored to the database via the binding.

Help! Again, I ask your patience as I'm rather new to this.

Robert
Apr 9 '08 #1
2 1263
DrBunchman
979 Expert 512MB
Hi Robert,

You can create a ListItem between the DropDownList tags for each option you want. Take a look at the following example:
Expand|Select|Wrap|Line Numbers
  1. <asp:DropDownList ID="ddColour" runat="server">
  2.      <asp:ListItem Text="RED" Value="0" />
  3.      <asp:ListItem Text="GREEN" Value="1" />
  4. </asp:DropDownList>
  5.  
I'm sure you can see how this works but let me know if you need any more assistance.

Hope this helps,

Dr B
Apr 10 '08 #2
Thanks for the response. Works perfectly. I'm still learning the nuances on this GridView stuff, I really appreciate you taking the time.

Robert
Apr 11 '08 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Isoaxis | last post by:
On the page in question I have a gridview that displays the list of all products in the Products table of the DB. That gridview is bound with a sqldatasource using Visual Studio's "wizards". The...
1
by: bill tie | last post by:
I have two dropDownLists A and B outside a gridView. A selection made in ddlA causes ddlB to be populated with data from the database. The gridView is populated with data according to a...
0
by: Mike P | last post by:
I know how to populate a dropdown list in a gridview in edit mode when the dropdown is populated by a datasource (see below eg 1), but how do you populate the dropdown when the dropdown is...
6
by: needin4mation | last post by:
I have a gridview and a dropdownlist. If I change the ddl, the gridview populates. That is what I want. But what I don't want is for it to happen the first time they get to the page. I know I...
2
by: Phil Sandler | last post by:
I am trying to do something which seems (to me) to be very simple, and yet I can't seem to figure it out. I have a gridview and a formview. When a user clicks "select" in the gridview, the...
0
by: koonda | last post by:
Hi all, I have a Project due after one week. It is a web service project. I have a Web Form which communicates to the web service and this web service communicates to the database. I have all my...
0
by: lamolap | last post by:
i have 1 gridview , a dropdownlist inside a gridview and a commandfield of (edit, update and cancel) my gidview looks like this Edit Surname Initials ...
0
by: Fabrizio | last post by:
Hi all. I have a field in a gridview as templatefield which is a label in view mode and a dropdownlist in edit mode with his datasource. This gridview is inserted as templatefield in another...
1
by: klaul | last post by:
I've been trying to do this for a day and a half now, and am clearly getting nowhere! The database I'm using is used to keep a log of service calls to various companies. When the user inserts data,...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.