• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 422
  • Last Modified:

asp.net/vb.net

I have an asp.net 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 vb.net as the code behind.

My code is


Code:
 dim i as integer
 dim myvar as string

        i = 1
        Do While i <= 12
            myvar = MonthName(i, True)
            cboMonth.Items.Add(myvar)
            i = i + 1
        Loop

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:


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

This wud have given me the desired result?

How to do in VB.NET (used as a code behind)?
0
rishaan
Asked:
rishaan
1 Solution
 
toddhdCommented:
       i = 1
        Do While i <= 12
            myvar = MonthName(i, True)
            dim LI as new ListItem(myvar,i)
            cboMonth.Items.Add(LI)
            i = i + 1
        Loop
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now