我有一个使用 PlaceHolder 的 ASP.NET 页面。网格以编程方式构建,并在页面运行时添加到此 PlaceHolder。例子:
ASPX 代码:
<asp:PlaceHolder ID="myPlaceHolder" runat="server" />
后面的代码:
foreach (var country in Tables.Countries())
{
var nGrid = BuildGrid(country.Code);
if (nGrid.Rows.Count > 0)
{
var lTitle = new Literal();
lTitle.Text = "<h2>Stats for country " + country.Name + "</h2>";
myPlaceHolder.Controls.Add(lTitle);
myPlaceHolder.Controls.Add(nGrid);
}
nGrid.Dispose();
}
private GridView BuildGrid(short countryCode)
{
GridView nGrid = new GridView();
nGrid.ID = "gr_" + countryCode;
nGrid.SkinID = "rpSkin";
nGrid.AutoGenerateColumns = false;
nGrid.AllowPaging = false;
nGrid.AllowSorting = false;
nGrid.RowStyle.VerticalAlign = VerticalAlign.Top;
nGrid.EnableViewState = false;
var nField = new BoundField
{
HeaderText = "People",
DataField = "PeopleCount"
};
nGrid.Columns.Add(nField);
// more BoundFields of this type exist
// This is basically the GridViewHelper class that gets Row Totals
// Disabling this doesn't help, either
HelpGrid(nGrid);
nGrid.DataSource = Country.GetPeople(countryCode);
nGrid.DataBind();
return nGrid;
}
此页面在 Opera 和 Firefox 中完美运行。Internet Explorer 8 显示“无法显示网页”屏幕。
有任何想法吗?