Index was out of range. Must be non-negative and less than the size of the collection. Parameter na

  • Thread starter Thread starter camelean
  • Start date Start date
C

camelean

I've been trying to correct this error for approx 2 days and am having
no luck.

In gridview.rowdatabound

Dim _dataKeyNames As String() = {"OFFICESUPPLY_ORDER_ID",
"STATUS_ID"}

gridview.DataKeyNames = _dataKeyNames


If e.Row.RowType = DataControlRowType.DataRow Then

gridview.DataKeys(e.Row.RowIndex)(1).ToString


End If

The app craps out at gridview.DataKeys(e.Row.RowIndex)(1).ToString on
row 0. the datakeynames are populated, there is a length of 2. I
just really am stuck.

Help is greatly appreciated.

Jason


Exception Details

System.ArgumentOutOfRangeException was caught
Message="Index was out of range. Must be non-negative and less than
the size of the collection.
Parameter name: index"
ParamName="index"
Source="mscorlib"
StackTrace:
at System.Collections.ArrayList.get_Item(Int32 index)
at System.Web.UI.WebControls.DataKeyArray.get_Item(Int32 index)
at cfoots_order_status.gridview_RowDataBound(Object sender,
GridViewRowEventArgs e) in
at
System.Web.UI.WebControls.GridView.OnRowDataBound(GridViewRowEventArgs
e)
at System.Web.UI.WebControls.GridView.CreateRow(Int32 rowIndex,
Int32 dataSourceIndex, DataControlRowType rowType, DataControlRowState
rowState, Boolean dataBind, Object dataItem, DataControlField[]
fields, TableRowCollection rows, PagedDataSource pagedDataSource)
at
System.Web.UI.WebControls.GridView.CreateChildControls(IEnumerable
dataSource, Boolean dataBinding)
at
System.Web.UI.WebControls.CompositeDataBoundControl.PerformDataBinding(IEnumerable
data)
at
System.Web.UI.WebControls.GridView.PerformDataBinding(IEnumerable
data)
at
System.Web.UI.WebControls.DataBoundControl.OnDataSourceViewSelectCallback(IEnumerable
data)
at
System.Web.UI.DataSourceView.Select(DataSourceSelectArguments
arguments, DataSourceViewSelectCallback callback)
at System.Web.UI.WebControls.DataBoundControl.PerformSelect()
at System.Web.UI.WebControls.BaseDataBoundControl.DataBind()
at System.Web.UI.WebControls.GridView.DataBind()
 
I've been trying to correct this error for approx 2 days and am having
no luck.

In gridview.rowdatabound

Dim _dataKeyNames As String() = {"OFFICESUPPLY_ORDER_ID",
"STATUS_ID"}

gridview.DataKeyNames = _dataKeyNames

If e.Row.RowType = DataControlRowType.DataRow Then

gridview.DataKeys(e.Row.RowIndex)(1).ToString

End If

The app craps out at gridview.DataKeys(e.Row.RowIndex)(1).ToString on
row 0. the datakeynames are populated, there is a length of 2. I
just really am stuck.

Help is greatly appreciated.

Jason

Exception Details

System.ArgumentOutOfRangeException was caught
Message="Index was out of range. Must be non-negative and less than
the size of the collection.
Parameter name: index"
ParamName="index"
Source="mscorlib"
StackTrace:
at System.Collections.ArrayList.get_Item(Int32 index)
at System.Web.UI.WebControls.DataKeyArray.get_Item(Int32 index)
at cfoots_order_status.gridview_RowDataBound(Object sender,
GridViewRowEventArgs e) in
at
System.Web.UI.WebControls.GridView.OnRowDataBound(GridViewRowEventArgs
e)
at System.Web.UI.WebControls.GridView.CreateRow(Int32 rowIndex,
Int32 dataSourceIndex, DataControlRowType rowType, DataControlRowState
rowState, Boolean dataBind, Object dataItem, DataControlField[]
fields, TableRowCollection rows, PagedDataSource pagedDataSource)
at
System.Web.UI.WebControls.GridView.CreateChildControls(IEnumerable
dataSource, Boolean dataBinding)
at
System.Web.UI.WebControls.CompositeDataBoundControl.PerformDataBinding(IEnu­merable
data)
at
System.Web.UI.WebControls.GridView.PerformDataBinding(IEnumerable
data)
at
System.Web.UI.WebControls.DataBoundControl.OnDataSourceViewSelectCallback(I­Enumerable
data)
at
System.Web.UI.DataSourceView.Select(DataSourceSelectArguments
arguments, DataSourceViewSelectCallback callback)
at System.Web.UI.WebControls.DataBoundControl.PerformSelect()
at System.Web.UI.WebControls.BaseDataBoundControl.DataBind()
at System.Web.UI.WebControls.GridView.DataBind()

Move first two lines out of the method

Dim _dataKeyNames As String() = {"OFFICESUPPLY_ORDER_ID",
"STATUS_ID"}
gridview.DataKeyNames = _dataKeyNames

You have to set the DataKeyNames property before you bound the
gridview

Dim _dataKeyNames As String() = {"OFFICESUPPLY_ORDER_ID",
"STATUS_ID"}
gridview.DataKeyNames = _dataKeyNames
gridview.DataSource = ...
gridview.DataBind()

Hope it helps
 
I've been trying to correct this error for approx 2 days and am having
no luck.
In gridview.rowdatabound
Dim _dataKeyNames As String() = {"OFFICESUPPLY_ORDER_ID",
"STATUS_ID"}
gridview.DataKeyNames = _dataKeyNames
If e.Row.RowType = DataControlRowType.DataRow Then

End If
The app craps out at gridview.DataKeys(e.Row.RowIndex)(1).ToString on
row 0. the datakeynames are populated, there is a length of 2. I
just really am stuck.
Help is greatly appreciated.

Exception Details
System.ArgumentOutOfRangeException was caught
Message="Index was out of range. Must be non-negative and less than
the size of the collection.
Parameter name: index"
ParamName="index"
Source="mscorlib"
StackTrace:
at System.Collections.ArrayList.get_Item(Int32 index)
at System.Web.UI.WebControls.DataKeyArray.get_Item(Int32 index)
at cfoots_order_status.gridview_RowDataBound(Object sender,
GridViewRowEventArgs e) in
at
System.Web.UI.WebControls.GridView.OnRowDataBound(GridViewRowEventArgs
e)
at System.Web.UI.WebControls.GridView.CreateRow(Int32 rowIndex,
Int32 dataSourceIndex, DataControlRowType rowType, DataControlRowState
rowState, Boolean dataBind, Object dataItem, DataControlField[]
fields, TableRowCollection rows, PagedDataSource pagedDataSource)
at
System.Web.UI.WebControls.GridView.CreateChildControls(IEnumerable
dataSource, Boolean dataBinding)
at
System.Web.UI.WebControls.CompositeDataBoundControl.PerformDataBinding(IEnu­merable
data)
at
System.Web.UI.WebControls.GridView.PerformDataBinding(IEnumerable
data)
at
System.Web.UI.WebControls.DataBoundControl.OnDataSourceViewSelectCallback(I­Enumerable
data)
at
System.Web.UI.DataSourceView.Select(DataSourceSelectArguments
arguments, DataSourceViewSelectCallback callback)
at System.Web.UI.WebControls.DataBoundControl.PerformSelect()
at System.Web.UI.WebControls.BaseDataBoundControl.DataBind()
at System.Web.UI.WebControls.GridView.DataBind()

Move first two lines out of the method

Dim _dataKeyNames As String() = {"OFFICESUPPLY_ORDER_ID",
"STATUS_ID"}
gridview.DataKeyNames = _dataKeyNames

You have to set the DataKeyNames property before you bound the
gridview

Dim _dataKeyNames As String() = {"OFFICESUPPLY_ORDER_ID",
"STATUS_ID"}
gridview.DataKeyNames = _dataKeyNames
gridview.DataSource = ...
gridview.DataBind()

Hope it helps

thank you very much. I had a feeling it was something simple like
this.
 
hello..
i want to do such that there exist a button from which when i click, there opens a new window. but it gives the error that index out of range.
i have this code in my RowDatabound event.

protected void PersonGridView_RowDataBound(object sender, GridViewRowEventArgs e)
{

var ID = PersonGridView.DataKeys[e.Row.RowIndex]["ID"].ToString();
if (e.Row.RowType == DataControlRowType.DataRow)
{
Button btnDetails = (Button)FindControl("Details");
Button btnModify = (Button)FindControl("Modify");
Button btnDelete = (Button)FindControl("Delete");
btnModify.CommandName = "Modify";
btnDelete.CommandName = "Delete";
btnDetails.CommandName = "Details";
btnDelete.CommandArgument = btnModify.CommandArgument = string.Format("{0}", ID);
btnDetails.Attributes["onclick"] = string.Format("viewProfile({0}); return false;", ID);


}
}



<head runat="server">
<script type="text/javascript">
function viewProfile(index,id)
{
var GridID = document.getElementById("PersonGridView");
var row=GridID.rows[parseInt(index)+1];
window.open('detailsid.aspx?'+id);
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:GridView ID="PersonGridView" runat="server" BackColor="White"
BorderColor="#DEDFDE" BorderStyle="None" BorderWidth="1px" CellPadding="4"
ForeColor="Black" GridLines="Vertical" AutoGenerateColumns="false"
onrowdatabound="PersonGridView_RowDataBound" DataKeyNames="ID"

onrowcommand="PersonGridView_RowCommand">
<RowStyle BackColor="#F7F7DE" />

<Columns>
<asp:BoundField HeaderText="First Name" DataField="FirstName" />
<asp:BoundField HeaderText="Last Name" DataField = "LastName" />
<asp:BoundField HeaderText="HomePhoneNumber" DataField="HomePhoneNumber" />
<asp:TemplateField HeaderText="ViewDetails">
<ItemTemplate>
<asp:Button ID="Deatils" runat="server" Text="Details" />
</ItemTemplate>

</asp:TemplateField>

<asp:TemplateField HeaderText="Actions">
<ItemTemplate>
<asp:Button ID="Modify" runat="server" Text="Modify" />
<asp:Button ID="Delete" runat="server" Text="Delete" />

</ItemTemplate>
</asp:TemplateField>


</Columns>


<FooterStyle BackColor="#CCCC99" />
<PagerStyle BackColor="#F7F7DE" ForeColor="Black" HorizontalAlign="Right" />
<SelectedRowStyle BackColor="#CE5D5A" Font-Bold="True" ForeColor="White" />
<HeaderStyle BackColor="#6B696B" Font-Bold="True" ForeColor="White" />
<AlternatingRowStyle BackColor="White" />
</asp:GridView>
</div>
</form>
</body>
I've been trying to correct this error for approx 2 days and am having
no luck.

In gridview.rowdatabound

Dim _dataKeyNames As String() = {"OFFICESUPPLY_ORDER_ID",
"STATUS_ID"}

gridview.DataKeyNames = _dataKeyNames


If e.Row.RowType = DataControlRowType.DataRow Then

gridview.DataKeys(e.Row.RowIndex)(1).ToString


End If

The app craps out at gridview.DataKeys(e.Row.RowIndex)(1).ToString on
row 0. the datakeynames are populated, there is a length of 2. I
just really am stuck.

Help is greatly appreciated.

Jason


Exception Details

System.ArgumentOutOfRangeException was caught
Message="Index was out of range. Must be non-negative and less than
the size of the collection.
Parameter name: index"
ParamName="index"
Source="mscorlib"
StackTrace:
at System.Collections.ArrayList.get_Item(Int32 index)
at System.Web.UI.WebControls.DataKeyArray.get_Item(Int32 index)
at cfoots_order_status.gridview_RowDataBound(Object sender,
GridViewRowEventArgs e) in
at
System.Web.UI.WebControls.GridView.OnRowDataBound(GridViewRowEventArgs
e)
at System.Web.UI.WebControls.GridView.CreateRow(Int32 rowIndex,
Int32 dataSourceIndex, DataControlRowType rowType, DataControlRowState
rowState, Boolean dataBind, Object dataItem, DataControlField[]
fields, TableRowCollection rows, PagedDataSource pagedDataSource)
at
System.Web.UI.WebControls.GridView.CreateChildControls(IEnumerable
dataSource, Boolean dataBinding)
at
System.Web.UI.WebControls.CompositeDataBoundControl.PerformDataBinding(IEnumerable
data)
at
System.Web.UI.WebControls.GridView.PerformDataBinding(IEnumerable
data)
at
System.Web.UI.WebControls.DataBoundControl.OnDataSourceViewSelectCallback(IEnumerable
data)
at
System.Web.UI.DataSourceView.Select(DataSourceSelectArguments
arguments, DataSourceViewSelectCallback callback)
at System.Web.UI.WebControls.DataBoundControl.PerformSelect()
at System.Web.UI.WebControls.BaseDataBoundControl.DataBind()
at System.Web.UI.WebControls.GridView.DataBind()
57 pm, (e-mail address removed) wrote:
nu=ADmerable
(I=ADEnumerable

Move first two lines out of the method

Dim _dataKeyNames As String() =3D {"OFFICESUPPLY_ORDER_ID",
"STATUS_ID"}
gridview.DataKeyNames =3D _dataKeyNames

You have to set the DataKeyNames property before you bound the
gridview

Dim _dataKeyNames As String() =3D {"OFFICESUPPLY_ORDER_ID",
"STATUS_ID"}
gridview.DataKeyNames =3D _dataKeyNames
gridview.DataSource =3D ...
gridview.DataBind()

Hope it helps
On Friday, October 31, 2008 3:32 AM tilak p wrote:
hiiiii

i have a asp.net page which contains gridview

after entering data to gridview and updating

in gridview i have given a save button on pressing it the data in grid will be sent to save function to

save in database but when i click save it shows

below error





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:

Parameter name: index



Source Error:



An unhandled exception was generated during the execution of the current web request.

Information regarding the origin and location of the exception can be identified using the exception stack trace below.



Stack Trace:





[ArgumentOutOfRangeException:

Parameter name: index]

DevExpress.Web.ASPxClasses.StateManagedCollectionInternal.System.Collections.IList.Insert(Int32 index, Object value) +161

DevExpress.Web.ASPxClasses.Collection.Insert(Int32 index, CollectionItem item) +44

DevExpress.Web.ASPxEditors.ListEditItemCollection.Insert(Int32 index, ListEditItem item) +33

DevExpress.Web.ASPxEditors.ListBoxProperties.SynchronizeItemsWithState(String stateString, Boolean isInsertingSyncroType) +198

DevExpress.Web.ASPxEditors.ASPxComboBox.SynchronizeItems(NameValueCollection postCollection) +187

DevExpress.Web.ASPxEditors.ASPxComboBox.LoadPostData(NameValueCollection postCollection) +48

DevExpress.Web.ASPxClasses.ASPxWebControl.LoadPostDataInternal(NameValueCollection postCollection, Boolean raisePostDataEvent) +218

DevExpress.Web.ASPxClasses.ASPxWebControl.System.Web.UI.IPostBackDataHandler.LoadPostData(String postDataKey, NameValueCollection postCollection) +35

System.Web.UI.Page.ProcessPostData(NameValueCollection postData, Boolean fBeforeLoad) +479

System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint









what is problem



plz help!!!

thanks in advance
 
Back
Top