I tring to use a dropdownbox using a Bson object(BsonDevise) but is not clear for me if i can use directly the object or need to enumerate to add a listItems. Can someone fix me the way.
Thanks.
public class BsonDevise
{
[BsonId]开发者_如何学编程
public String Id { get; set; }
[BsonIgnore]
public Guid ID
{
get
{
if (!String.IsNullOrEmpty(Id))
return new Guid(Id);
return new Guid();
}
set { Id = value.ToString(); }
}
public String deviseID { get; set; }
public String isoCountry { get; set; }
public string Symbol { get; set; }
}
protected void Page_Load(object sender, EventArgs e)
{
//Initialise Dropdownselectors
List<BsonDevise> dev = new List<BsonDevise>();
using (BsonHelper helper = BsonService.Helpers.BsonHelper.Create())
{
dev = helper.Devises.DeviseRepository.GetAllDevises();
}
//Drill ddlCountry
ListItem item = new ListItem();
item.Text = "Devise";
item.Value = "-1";
ddlCodeDevise.Items.Add(item);
ddlCodeDevise.DataSource = dev;
ddlCodeDevise.DataTextField = "deviseID";
ddlCodeDevise.DataValueField = "deviseID";
}
What you have should work, You just need to bind the ddl.
protected void Page_Load(object sender, EventArgs e)
{
//Initialise Dropdownselectors
List<BsonDevise> dev = new List<BsonDevise>();
using (BsonHelper helper = BsonService.Helpers.BsonHelper.Create())
{
dev = helper.Devises.DeviseRepository.GetAllDevises();
}
//Drill ddlCountry
ListItem item = new ListItem();
item.Text = "Devise";
item.Value = "-1";
ddlCodeDevise.Items.Add(item);
ddlCodeDevise.DataSource = dev;
ddlCodeDevise.DataTextField = "deviseID";
ddlCodeDevise.DataValueField = "deviseID";
//bind ddl to list
ddlCodeDevise.DataBind();
}
精彩评论