CSS Friendly 中的DetailsView的问题
在实现NBearDataSource控件 - 02-11 20:30 修订 - 新增Master/Detail实体CRUD示例 介绍了基于NBearDataSource的Master/Detail实体CRUD示例
若使用CSS Friendly ASP.NET 2.0 Control Adapters 1.0 的,如下代码
只要将DetailsView设置属性DefaultMode="Insert" AutoGenerateInsertButton="true" AutoGenerateRows="false"
就会出现异常:
索引超出范围。必须为非负值并小于集合大小。
说明: 执行当前 Web 请求期间,出现未处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。
异常详细信息: System.ArgumentOutOfRangeException: 索引超出范围。必须为非负值并小于集合大小。
参数名: index
源错误:
源文件: XXXXX\WebSite\App_Code\Adapters\DetailsViewAdapter.cs 行: 59
我将源代码修改了一下,这样可以工作了
若使用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>
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
2
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
3
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
4
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
5
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
6
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
7
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
8
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
9
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
只要将DetailsView设置属性DefaultMode="Insert" AutoGenerateInsertButton="true" AutoGenerateRows="false"
就会出现异常:
索引超出范围。必须为非负值并小于集合大小。
参数名: index
说明: 执行当前 Web 请求期间,出现未处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。 异常详细信息: System.ArgumentOutOfRangeException: 索引超出范围。必须为非负值并小于集合大小。
参数名: index
源错误:
|
源文件: XXXXX\WebSite\App_Code\Adapters\DetailsViewAdapter.cs 行: 59
我将源代码修改了一下,这样可以工作了
1
DetailsViewRow 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![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
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
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
2
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
3
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
4
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
5
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
6
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
7
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
8
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
9
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
10
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
11
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
12
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
13
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
14
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
15
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
16
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
17
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
18
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockEnd.gif)
19
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)