【问题标题】:How to pass list as parameter to a method in .aspx page如何将列表作为参数传递给.aspx页面中的方法
【发布时间】:2013-09-30 12:30:38
【问题描述】:

我必须将 gridview 绑定到返回 list<> 的方法,列表中的多选查找很少,为此我有一个返回 dictionary<int, string> 的方法。

在列表中,我的多选项目值为{1, xyz}, {2, abc}

所以我必须在网格中显示为 xyz, abc。

为此,我编写了一个方法 FormatString,它在 gridview 绑定中调用.. 即 aspx 页面

<%# FormatString(?????????) %>

我必须通过list<> 在????检索数据..

请给我一些解决方案..

【问题讨论】:

标签: c# asp.net


【解决方案1】:
'<%# FormatString(Container.DataItem as YourListType) %>'

public String FormatString(YourListType listObj )
{
   //do what  you want.
}

【讨论】:

    【解决方案2】:

    你可以试试这个方法

    从字典项中获取不同列表的值

    var items = yourDictionary.Values.SelectMany(x => x).ToList();
    

    然后你可以简单地将列表绑定到gridview

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-11-06
      • 2018-08-27
      • 1970-01-01
      • 2013-01-24
      • 2013-05-22
      • 1970-01-01
      • 2018-02-12
      • 1970-01-01
      相关资源
      最近更新 更多