【问题标题】:Bind the data to the gridview将数据绑定到gridview
【发布时间】:2013-06-06 14:20:40
【问题描述】:

我像这样从数据库中填充我的列表。

List<BObj_person> list = new List<BObj_person>();

BObj_person person = new BObj_person
                    {
                        PersonName = "aaa",
                        PersonSurname = "bbbb",
                        departman = new BObj_departman { DepartmanName = "ccc" }
                    };

list = list.Add(person);

PersonNamePersonSurname 没问题,它显示在网格内但departmanName 有问题?? 我怎样才能像这样将此列表绑定到datagridview; gridview.DataSource = list;

**我正在使用 Ext.Net 网格 谢谢。

【问题讨论】:

  • list=list.Add(person); ? Add 方法无效 - 只需执行 list.Add(person)

标签: c# asp.net gridview ext.net


【解决方案1】:

您可以将 ServerMapping 用于 ModelField。

<ext:ModelField Name="departmanName" ServerMapping="departman.Name;" />

<ext:Column runat="server" DataIndex="departmanName" />

这里是a full example of using ServerMapping

【讨论】:

    【解决方案2】:

    这应该可以,但我可能误解了你的问题

    <%# Eval("departman.DepartmanName") %>
    

    如果您想简化绑定,可以向 BObj_person 添加一个名为 DepartmanName 的只读属性

    public class BObj_person
    {
        ...
        public string DepartmanName 
        { 
           get { return departman.Name; }
        }          
    }    
    

    【讨论】:

      【解决方案3】:

      用集合设置gridview的DataSource然后

      <asp:TemplateField>
          <itemtemplate>
              <p><%#DataBinder.Eval(Container.DataItem, "departman.DepartmanName")%></p>
          </itemtemplate>
      </asp:TemplateField>
      

      【讨论】:

        【解决方案4】:

        您应该使用 gridview.ItemsSource。这应该足以让它工作。

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2012-06-17
          • 2012-02-01
          • 2013-03-31
          • 2012-03-08
          相关资源
          最近更新 更多