例子:
<asp:GridView ID="reportScheduleDetailsGridView" runat="server" AutoGenerateColumns="False" >
<Columns>
<asp:BoundField DataField="Name" HeaderText="Name" ></asp:BoundField>
<asp:BoundField DataField="Frequency" HeaderText="Frequency" ></asp:BoundField>
<asp:TemplateField HeaderText="Reports" >
<ItemTemplate>
<asp:Label ID="cblSubscribedReports" Text='<%# Eval("Reports") %>' runat="server"/>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
代码:
DataTable table = new DataTable();
table.Columns.Add("Name");
table.Columns.Add("Frequency");
table.Columns.Add("Reports");
DataRow row1 = table.NewRow();
row1["Name"] = "A";
row1["Frequency"] = "Daily";
List<string> report1 = new List<string>();
report1.Add("XYZ");
report1.Add("ABC");
report1.Add("PQR");
row1["Reports"] = report1;
table.Rows.Add(row1);
DataRow row2 = table.NewRow();
row2["Name"] = "B";
row2["Frequency"] = "Weekly";
List<string> report2 = new List<string>();
report2.Add("XYZ");
row2["Reports"] = report2;
table.Rows.Add(row2);
reportScheduleDetailsGridView.DataSource = table;
reportScheduleDetailsGridView.DataBind();
当我运行代码报告列显示 System.Collections.Generic 而不是字符串值
Name Frequency Reports
A Daily System.Collections.Generic.List`1[System.String]
B Weekly System.Collections.Generic.List`1[System.String]
我需要这样的输出:报告列应该显示字符串列表
Name Frequency Reports
A Daily 1.XYZ
2.ABC
3.PQR
B Weekly 1.XYZ