Solved

ASP.NET Inserting field using static dropdownlist

Posted on 2011-09-16
4
240 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 250 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Icons and Colors for Terms 3 24
Code works but I need to redo it and assign values to Model 7 32
Problem with Filesystemobject or .NET version 3 34
ASP.NET 5 Templates 2 65
Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to us…

912 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

Need Help in Real-Time?

Connect with top rated Experts

24 Experts available now in Live!

Get 1:1 Help Now