显示嵌套的匿名类型 [英] displaying nested anonymous type
本文介绍了显示嵌套的匿名类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如果您能帮助我解决问题,我将不胜感激.我试图在GridView控件中显示嵌套的匿名类型.但是GridView控件仅显示OrderID
和OrderDate
字段(即它不显示嵌套类型).
我正在使用以下代码:
I would be grateful if you could help me to solve the problem. Im trying to display a nested anonymous type in a GridView control. But the GridView control displaying only OrderID
and OrderDate
fields (i.e. it doesn''t display nested type).
I''m using the following code:
protected void btn2_Click(object sender, EventArgs e)
{
var query = (from o in ctx2.Orders
select new
{o.OrderID, o.OrderDate,
nest_anon = new {
o.Customer,
o.ShipAddress,
o.Status }});
tb2.Text = (query as ObjectQuery).ToTraceString();
gv2.DataSource=query;
gv2.DataBind();
我应该在代码中解决什么才能在GridView中显示匿名和嵌套的匿名类型?预先谢谢您.
What should i fix in my code to display anonymous and nested anonymous type in my GridView? Thank you in advance.
推荐答案
好,现在我明白了您的意思.
您所要做的就是将gridview的AutoGenerateColumns属性设置为false.然后应用列模板.您需要在这一行上编辑aspx.
ok, now I get what you mean.
All you have to do is set the AutoGenerateColumns property of the gridview to false. Then apply a column templates. You need to edit your aspx on this one.
<asp:GridView ID="grdMain" runat="server" AutoGenerateColumns="False">
<columns>
<asp:BoundField DataField="OrderID" HeaderText="OrderID" />
<asp:BoundField DataField="OrderDate" HeaderText="OrderDate" />
<asp:BoundField DataField="nest_anon" HeaderText="Nested Type" />
</columns>
</asp:GridView>
我不确定您要做什么,您是否尝试过:
I''m not really sure what you''re trying to do, have you tried:
gv2.DataSource = query.ToList();
这篇关于显示嵌套的匿名类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文