绑定列表<;收藏<;字符串>&燃气轮机;在asp.net中创建网格视图
我有一个绑定列表<;收藏<;字符串>&燃气轮机;在asp.net中创建网格视图,asp.net,list,gridview,Asp.net,List,Gridview,我有一个列表对象,其中包含10000个对象,我想将这些字符串显示为报表(在网格视图中),但将该对象直接绑定到网格不会产生任何结果。因此,有人可以帮助我如何将字符串集合绑定为不同的列,并使用我需要的标题名。您可以使用[]索引以绑定数据源(字符串/数组列表)项 标记: <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"> <
列表
对象,其中包含10000个对象,我想将这些字符串显示为报表(在网格视图中),但将该对象直接绑定到网格不会产生任何结果。因此,有人可以帮助我如何将字符串集合绑定为不同的列,并使用我需要的标题名。您可以使用[]
索引以绑定数据源(字符串/数组列表)项
标记:
<asp:GridView ID="GridView1"
runat="server"
AutoGenerateColumns="False">
<Columns>
<asp:TemplateField>
<ItemTemplate>
<asp:Literal
ID="Literal1"
runat="server"
Text='<%#Eval("[0]") %>'
>
</asp:Literal>
<asp:Literal
ID="Literal2"
runat="server"
Text='<%#Eval("[1]") %>'
>
</asp:Literal>
<asp:Literal
ID="Literal3"
runat="server"
Text='<%#Eval("[2]") %>'
>
</asp:Literal>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
代码隐藏:
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
List<List<string>> list = new List<List<string>>()
{
new List<string>() {"A","B","C" },
new List<string>() { "P","Q","R"}
};
GridView1.DataSource = list;
GridView1.DataBind();
}
}
受保护的无效页面加载(对象发送方,事件参数e)
{
如果(!IsPostBack)
{
列表=新列表()
{
新列表(){A”,“B”,“C”},
新列表(){“P”、“Q”、“R”}
};
GridView1.DataSource=列表;
GridView1.DataBind();
}
}
您可以使用[]
索引绑定数据源(字符串/数组列表)项
标记:
<asp:GridView ID="GridView1"
runat="server"
AutoGenerateColumns="False">
<Columns>
<asp:TemplateField>
<ItemTemplate>
<asp:Literal
ID="Literal1"
runat="server"
Text='<%#Eval("[0]") %>'
>
</asp:Literal>
<asp:Literal
ID="Literal2"
runat="server"
Text='<%#Eval("[1]") %>'
>
</asp:Literal>
<asp:Literal
ID="Literal3"
runat="server"
Text='<%#Eval("[2]") %>'
>
</asp:Literal>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
代码隐藏:
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
List<List<string>> list = new List<List<string>>()
{
new List<string>() {"A","B","C" },
new List<string>() { "P","Q","R"}
};
GridView1.DataSource = list;
GridView1.DataBind();
}
}
受保护的无效页面加载(对象发送方,事件参数e)
{
如果(!IsPostBack)
{
列表=新列表()
{
新列表(){A”,“B”,“C”},
新列表(){“P”、“Q”、“R”}
};
GridView1.DataSource=列表;
GridView1.DataBind();
}
}
但它不适用于在不同列中显示不同的字符串,而是在同一列中显示所有字符串?@vinaysingri-使用templatefield columns.AVD您的意思是说单独文本的单独模板字段标记是吗???@vinaysingri-是的!这是真的。但它不适用于在不同列中显示不同的字符串,而是在同一列中显示所有字符串?@vinaysingri-使用TempleteField columns.AVD您的意思是说单独的文本的单独模板字段标记是吗???@vinaysingri-是的!这是真的。