CSS Friendly 中的DetailsView的問題

來源:互聯網
上載者:User
在實現NBearDataSource控制項 - 02-11 20:30 修訂 - 新增Master/Detail實體CRUD樣本 介紹了 基於NBearDataSource的Master/Detail實體CRUD樣本

若使用CSS Friendly ASP.NET 2.0 Control Adapters 1.0 的,如下代碼
1<nb:NBearDataSource ID="nbdsLinkCategorys" runat="server" ConnectionStringName="Access"
2        TypeName="MK2.Community.Entities.LinkCategory" EnableViewState="true">
3        </nb:NBearDataSource>
4        <asp:DetailsView ID="DetailsView1" runat="server" DataSourceID="nbdsLinkCategorys" DefaultMode="Insert"
5         AutoGenerateInsertButton="true" AutoGenerateRows="false">
6            <Fields>
7                <asp:BoundField DataField="Name" HeaderText="Name" />
8            </Fields>
9        </asp:DetailsView>

只要將DetailsView設定屬性DefaultMode="Insert" AutoGenerateInsertButton="true" AutoGenerateRows="false"
就會出現異常:
索引超出範圍。必須為非負值並小於集合大小。
參數名: index

說明: 執行當前 Web 請求期間,出現未處理的異常。請檢查堆疊追蹤資訊,以瞭解有關該錯誤以及代碼中導致錯誤的出處的詳細資料。

異常詳細資料: System.ArgumentOutOfRangeException: 索引超出範圍。必須為非負值並小於集合大小。
參數名: index

源錯誤:

行 57:                     {            行 58:                         DetailsViewRow row = ControlAsDetailsView.Rows[iRow];            行 59:                         if ((!ControlAsDetailsView.AutoGenerateRows) &&            行 60:                             ((row.RowState & DataControlRowState.Insert) == DataControlRowState.Insert) &&            行 61:                             (!ControlAsDetailsView.Fields[row.RowIndex].InsertVisible))

源檔案: XXXXX\WebSite\App_Code\Adapters\DetailsViewAdapter.cs    行: 59

我將原始碼修改了一下,這樣可以工作了 1DetailsViewRow row = ControlAsDetailsView.Rows[iRow];
 2                        //if ((!ControlAsDetailsView.AutoGenerateRows) &&
 3                        //    ((row.RowState & DataControlRowState.Insert) == DataControlRowState.Insert) &&
 4                        //    (!ControlAsDetailsView.Fields[row.RowIndex].InsertVisible))
 5                        //{
 6                        //    continue;
 7                        //}
 8
 9                        //Fix by MK2
10                        if ((!ControlAsDetailsView.AutoGenerateRows) &&
11                            ((row.RowState & DataControlRowState.Insert) == DataControlRowState.Insert))
12                        {
13                            if ((iRow < ControlAsDetailsView.Fields.Count) && 
14                                (!ControlAsDetailsView.Fields[row.RowIndex].InsertVisible))
15                            {
16                                continue;
17                            }
18                        }
19                        //Fix over

相關文章

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.