Asp.net 将DropDownList绑定到IEnumerable

Asp.net 将DropDownList绑定到IEnumerable,asp.net,Asp.net,我有一个方法: public static IEnumerable<Datarow> getInfo (string test) { some functionality and adds two columns in datatable dt. now how can i return dt from this method (question 1) } 公共静态IEnumerable getInfo(字符串测试) { 添加一些功能并在datatable dt中添

我有一个方法:

public static IEnumerable<Datarow> getInfo (string test)
{
    some functionality and adds two columns in datatable dt.

   now how can i return dt from this method (question 1)
}
公共静态IEnumerable getInfo(字符串测试)
{
添加一些功能并在datatable dt中添加两列。
现在我如何从这个方法返回dt(问题1)
}
我必须将方法返回的值绑定到名为
ddlist
的下拉列表中

我怎样才能做到这一点

(问题二) .. 当我尝试时,我得到了无法绑定ienumerable的消息


请帮助我。

您可以更改返回数据表或通过IEnumerable循环的方法,并手动添加列表项

查看这篇博客文章,了解你尝试做什么的另一种方法

博客中的代码示例(不是我的):


如果我是你,我会为问题选择一个反映问题性质的标题。你问题的标题绝不会说明问题的主题。你的Q需要正确的格式和结构良好的查询……对此我深表歉意。我正在尝试编辑我的标题。是否有任何方法可以删除此问题并开始新的回答,我必须将方法设置为public Ienumerable getinfo,如果要返回datatable,我是否可以简单地返回项?
public IEnumerable GetDataSource() {
    string key = "CodeDrowDownListTest_" + CodeName;

    object item = Page.Cache.Get(key);
    if (item == null)
    {
        item = GetDataFromDB();
        Page.Cache.Insert(key, item, null, System.DateTime.UtcNow.AddHours(1), System.Web.Caching.Cache.NoSlidingExpiration);
    }

    return (IEnumerable)item; }

 public override void DataBind() {
    this.DataSource = GetDataSource();
    this.DataTextField = "Text";
    this.DataValueField = "Value";

    base.DataBind();
}