Posted on 2005-04-28
Last Modified: 2010-04-23
I have an control Combo Box. I want to pouplate it with the
name of the months.

I am wring the code in the code behind. I am using as the code behind.

My code is

 dim i as integer
 dim myvar as string

        i = 1
        Do While i <= 12
            myvar = MonthName(i, True)
            i = i + 1

I get the populated month names in the combobox, because of the
function MonthName.

But in the value I want 1,2,3 not Jan, Feb, Mar...How to achive
this?Right now I am getting,

<option value="Jan">Jan</option>
<option value="Feb">Feb</option>
<option value="Dec">Dec</option>

rather I want

<option value=1>Jan</option>
<option value=2>Feb</option>
<option value=12>Dec</option>

Had been it ASP I wud have written:

do while iLoop <= 12
  myvar = MonthName(iLoop,true)
    Response.Write "<option value=" & iLoop & ">" & myvar & "</option>"
  iLoop = i Loop+1

This wud have given me the desired result?

How to do in VB.NET (used as a code behind)?
Question by:rishaan
    1 Comment
    LVL 8

    Accepted Solution

           i = 1
            Do While i <= 12
                myvar = MonthName(i, True)
                dim LI as new ListItem(myvar,i)
                i = i + 1

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Why You Should Analyze Threat Actor TTPs

    After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

    I think the Typed DataTable and Typed DataSet are very good options when working with data, but I don't like auto-generated code. First, I create an Abstract Class for my DataTables Common Code.  This class Inherits from DataTable. Also, it can …
    The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (…
    It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
    Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

    761 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

    14 Experts available now in Live!

    Get 1:1 Help Now