Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

ASP.NET Inserting field using static dropdownlist

Posted on 2011-09-16
4
Medium Priority
?
265 Views
Last Modified: 2012-06-21
I have a small form I use to add new records to an sql table and I want one field to be selected from a dropdownlist of two possible options. The options will actually be the current month and the previous month, I also want the drop down to default to the current month, or the first item.

I'm getting tied-up in thinking how I can setup a static drop down which I can populate in the aspx page but then also have this bound to a data field. I'm sure it's not rocket science but I'm darned if I can figure it out and keep going around in circles.

Any help appreciated, thanks.
0
Comment
Question by:nigelr99
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
4 Comments
 
LVL 16

Expert Comment

by:Easwaran Paramasivam
ID: 36547975
http://www.daniweb.com/web-development/aspnet/threads/123836

Dropdown.Items.Add("saticvalue");  //used to add static value'


//From database
Dropdown.Items.Clear();
Dropdown.Datasource= datasource;
Dropdown.DataBind();
0
 
LVL 1

Expert Comment

by:bolt81
ID: 36547994
Also if you are looking to type in values in the collect (on the aspx page) as well as having databound items you set the "AppendDataBoundItems" property to true.
0
 

Author Comment

by:nigelr99
ID: 36548076
Not sure I've worded my question very well - it's only relating to inserting new records.

My thinking is now I just add 2 items to a static dropdown in the form, then set the relevant field in the form view.iteminserting event before the insert. Is there a more efficient way than this?
0
 
LVL 7

Accepted Solution

by:
Kishan Zunjare earned 1000 total points
ID: 36553777
' Initialise month
' Fill month drop down
For month As Integer = 1 To 12
           ddlMonth.Items.Add(New ListItem(month.ToString(), month.ToString()))
Next

' Set to current month
ddlMonth.SelectedValue = DateTime.Now.Month.ToString()

Hope this will work.
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…

636 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question