0

如何将多个数据源设置为单个下拉列表?

 DrpPosition.ClearSelection();
        DrpPosition.DataSource = AdvertizeManager.GetList("", "", "", "");
        DrpPosition.DataTextField = "PNAME";
        DrpPosition.DataValueField = "ADID";
        DrpPosition.DataBind();
        DrpPosition.DataSource = CategoryManager.GetList("", "", "", "");
        DrpPosition.DataTextField = "NAME";
        DrpPosition.DataValueField = "CATID";
        DrpPosition.DataBind();
4

2 回答 2

1

您可以使用 LINQ 轻松解决此问题:

        var advertizes = AdvertizeManager.GetList...
        var categories = CategoryManager.GetList....

        // create your annonymous type
        var customAdvertizes = from advertize in advertizes
                select new
                {
                    Value = advertize.ADID,
                    Text = advertize.PNAME
                };

        var finalQuery = customAdvertizes.Concat(
            from category in categories
            select new
            {
                Value = category.CATID,
                Text = category.NAME
            }
        );

然后把它绑定到你的DropDownList

    DrpPosition.DataSource = finalQuery;
    DrpPosition.DataTextField = "Text";
    DrpPosition.DataValueField = "Value";
    DrpPosition.DataBind();
于 2012-08-01T08:40:46.033 回答
0

这是不可能的,但您可以在绑定之前合并您的数据源。

或者你可以使用

foreach(var item in yourDataSourceComplete)//yourDataSourceComplete = List1 + List2
{ 
  .....
  DrpPosition.Items.Add(Yourkey, YourValue);
}
于 2012-08-01T08:30:26.243 回答