Showing posts with label combobox. Show all posts
Showing posts with label combobox. Show all posts

Saturday, March 24, 2012

Populate Month in Combobox <Resolved>

Hi!

I have a 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

'Month
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 month name.

But in the value I want 1,2,3 not Jan, Feb, Mar...How to achive this.

Had been it ASP I wud have written:

do while iLoop <= 12
myvar = MonthName(iLoop,true)
Response.Write "<option value=" & iLoop & " selected>" & myvar & "</option>"
iLoop = i Loop+1
loop
This wud have given me the dsired result.

How to do in VB.NET?With a bit of R&D got the solution:

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

Friday, March 16, 2012

Populating ComboBox From Dataset

Hi Guys,

I need to populate a combobox from a dataset returned from a webservice. I set the datasource property of the control to the web method but got an empty list at run time! What am I doing wrong? Any help on how to achieve this? Looping through a datareader solved the problem but I want to consume a dataset from a web service. I thought this would be a straight stuff but I'm having problems with it.After setting the datasource property you have to bind the data to your controll.

It seems you are missing that bit.
I can handle that with DropDownList control in ASP.Net but not with ComboBox in Windows Application! Could you kindly show how syntactically?
Are you getting an error?
What does it say?

Post your code so that we can see more clearly what has gone wrong
I am not getting any error message! I only get this wierd entry in the ComboBox. "System.Data.DataViewManagerListItemTypeDescriptor"

This is the code that I used.

Private Sub Users_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim wsDemo As New ng_app001_pc_stock.PCInventory
ComboBox1.datasource = wsDemo.getAllOSTypes
End Sub

The webmethod getAllOSTypes works well, at least I tested it with DataGrid control. What could be wrong?