Solved

ASP.NET Inserting field using static dropdownlist

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

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

762 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

17 Experts available now in Live!

Get 1:1 Help Now