GridView
列を手動で生成しているときに問題があります。私のHTMLコードがあるGridView.AutoGenerateColumns falseの場合、セル番号の制限はありますか?
"Specified argument was out of the range of valid values. Parameter name: index Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.ArgumentOutOfRangeException: Specified argument was out of the range of valid values. Parameter name: index"
:
<div class="scrolling-container">
<br/>
<asp:GridView EnableSortingAndPagingCallbacks="true" ID="StationGridView" runat="server"
GridLines="None" CellSpacing="1" AlternatingRowStyle-Wrap="false"
Font-Names="tahoma" Font-Size="14px" CellPadding="3"
AllowSorting="True"
ViewStateMode="Disabled" EnableViewState="false"
AllowPaging="True" PageSize="15" dir="rtl" Width="100%"
OnRowDataBound="StationGridView_RowDataBound">
<HeaderStyle BackColor="#d7effd" Font-Bold="true" ForeColor="Navy" Font-Size="12px" Font-Underline="false" />
<FooterStyle BackColor="#d7effd" Font-Bold="true" ForeColor="Navy"
VerticalAlign="Middle" HorizontalAlign="Center" Font-Size="16px" />
<AlternatingRowStyle BackColor="#c0c0c0" ForeColor="#000000" Height="25px" />
</asp:GridView>
</div>
私のソースコードは次のとおりです。
protected void Page_Load(object sender, EventArgs e)
{
if (Page.IsPostBack == false)
{
Initialize();
}
//Load data
PortalDataSetTableAdapters.VW_StationTableAdapter stationsAdapter = new PortalDataSetTableAdapters.VW_StationTableAdapter();
PortalDataSet.VW_StationDataTable Station;
Station = stationsAdapter.GetData();
StationGridView.DataSource = Station;
StationGridView.AutoGenerateColumns = true;
StationGridView.DataBind();
}
}
protected void StationGridView_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.Header)
{
e.Row.Cells[0].Text = "a";
e.Row.Cells[1].Text = "b";
e.Row.Cells[2].Text = "c";
.
.
e.Row.Cells[42].Text = "x";
e.Row.Cells[43].Text = "x";
e.Row.Cells[44].Text = "x";
}
}
私のプログラムは、この行で停止:
e.Row.Cells[42].Text = "x";
と、以下のエラーがスローされます
麻痺(正確にはe.Row.Cells[42].Text = "x";
という行に)42以上のセルが生成されている場合、エラーが発生します。なぜこれが起こるのですか?
その行には42のセルしかないので(41 +第0行、42となる)あなたはなぜその行に42以上の細胞があると思いますか? – Draken