After implementing the NBearDataSource control-02-11 revision-added the Master/Detail object CRUD example
Example of a Master/Detail object CRUD Based on NBearDataSource
If you use CSS Friendly ASP. NET 2.0 Control Adapters 1.0, the following code
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" performanceid = "nbdsLinkCategorys" DefaultMode = "Insert"
5 AutoGenerateInsertButton = "true" AutoGenerateRows = "false">
6 <Fields>
7 <asp: BoundField DataField = "Name" HeaderText = "Name"/>
8 </Fields>
9 </asp: DetailsView>
You only need to set the DetailsView attribute DefaultMode = "Insert" AutoGenerateInsertButton = "true" AutoGenerateRows = "false"
An exception occurs:
The index is out of the range. It must be a non-negative value and smaller than the set size.
Parameter Name: index
Note:An error occurred while executing the current Web request. Check the stack trace information for details about the error and the source of the error in the code.
Exception details:System. ArgumentOutOfRangeException: The index is out of the range. It must be a non-negative value and smaller than the set size.
Parameter Name: index
Source error:
Row 57: {row 58: DetailsViewRow row = ControlAsDetailsView. Rows [iRow]; row 59: if ((! ControlAsDetailsView. AutoGenerateRows) & row 60: (row. RowState & DataControlRowState. Insert) = DataControlRowState. Insert) & row 61 :(! ControlAsDetailsView. Fields [row. RowIndex]. InsertVisible ))
|
Source file:XXXXX \ WebSite \ App_Code \ Adapters \ DetailsViewAdapter. csRow:59
I modified the source code, so that I can work with 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
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