Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

ASP.NET Inserting field using static dropdownlist

Posted on 2011-09-16
4
Medium Priority
?
273 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
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

Veeam Disaster Recovery in Microsoft Azure

Veeam PN for Microsoft Azure is a FREE solution designed to simplify and automate the setup of a DR site in Microsoft Azure using lightweight software-defined networking. It reduces the complexity of VPN deployments and is designed for businesses of ALL sizes.

Question has a verified solution.

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

A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
Hello there! As a developer I have modified and refactored the unit tests which was written by fellow developers in the past. On the course, I have gone through various misconceptions and technical challenges when it comes to implementation. I would…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an anti-spam), the admin…
Look below the covers at a subform control , and the form that is inside it. Explore properties and see how easy it is to aggregate, get statistics, and synchronize results for your data. A Microsoft Access subform is used to show relevant calcul…
Suggested Courses

810 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