2016-07-20 20 views
1

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以上のセルが生成されている場合、エラーが発生します。なぜこれが起こるのですか?

+0

その行には42のセルしかないので(41 +第0行、42となる)あなたはなぜその行に42以上の細胞があると思いますか? – Draken

答えて

0

あなたが行の十億を持っていない場合は、列がここに (ソース:http://forums.asp.net/post/3380845.aspx)の問題ではありませんカウント

あなたは確かに唯一の42列を持っている、とあなたが43thに到達しようとしているとき、あなたはArugmentOutOfRangeExceptionを取得します。

+0

私のクエリは約1000以上のレコードを持っていますが、グリッドビューのレコード数を取得すると42です。理由はわかりません。私のモデル(app_codeフォルダ内のmydataset.xsdファイル)でクエリを実行しても、完全なデータが返されます –

+0

これで問題は行数ですか? (レコード=行ですか?) 私はあなたを助ける方法がわかりません、ごめんなさい –

関連する問題