DataBinding with Array contents

D

D. Shane Fowlkes

This should be easy but I'm having a little trouble connecting the logical
dots. I have a function which simply returns the 12 month names. Whoopie.
I'm trying to store that data into an ArrayList and this arraylist is
created when a function is called. After calling the function, I'm trying
to bind this array to a DropDownList. All this up to this point seems to
work.

But what I'd LIKE to do is have the value of the DropDown list items be the
INDEX of the array instead of the literal month name. So instead of :
<option value="January">January</option>

I'd like:
<option value="1">January</option>

But I'm not quite sure how to bind the Index too. Any suggestions and more
importantly, any pointers on a better way of doing this?

Thanks!!

http://www.drumpub.com/months.aspx (sample and source code)
 
T

Teemu Keiski

Hi,

this way you can't unless you loop through items in ArrayList and create
ListItems manually for the DDL. To be able to do it via databinding create
custom Month object that you create for every month, then you could access
this objects's properties in DataValueField and dataTextField properties of
DDL. Third option would be just using : DateTimeFormatInfo.MonthNames or
just hardcode them...

-
Teemu Keiski
MCP, Microsoft MVP (ASP.NET), AspInsiders member
ASP.NET Forum Moderator, AspAlliance Columnist




This should be easy but I'm having a little trouble connecting the logical
dots. I have a function which simply returns the 12 month names. Whoopie.
I'm trying to store that data into an ArrayList and this arraylist is
created when a function is called. After calling the function, I'm trying
to bind this array to a DropDownList. All this up to this point seems to
work.

But what I'd LIKE to do is have the value of the DropDown list items be the
INDEX of the array instead of the literal month name. So instead of :
<option value="January">January</option>

I'd like:
<option value="1">January</option>

But I'm not quite sure how to bind the Index too. Any suggestions and more
importantly, any pointers on a better way of doing this?

Thanks!!

http://www.drumpub.com/months.aspx (sample and source code)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top