开发者

MongoDB C# offi: Drill Dropdownboxes with Bson objects

开发者 https://www.devze.com 2023-02-14 17:14 出处:网络
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.

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();
}
0

精彩评论

暂无评论...
验证码 换一张
取 消