Solved

ASP.NET Inserting field using static dropdownlist

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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

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…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

739 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