index out of range error

G

Guest

When I run the following code:

private void applicationPermissionGrid_ItemDataBound(object sender,
System.Web.UI.WebControls.DataGridItemEventArgs e)
{

if (e.Item.ItemType == System.Web.UI.WebControls.ListItemType.Item ||
(e.Item.ItemType ==
System.Web.UI.WebControls.ListItemType.AlternatingItem))
{
if(applicationPermissionGrid.Items[e.Item.ItemIndex].Cells[6].Text == "0")
{
applicationPermissionGrid.Items[e.Item.ItemIndex].Cells[0].Text = "NO";
}
}

I get the following error:



Index was out of range. Must be non-negative and less than the size of the
collection. 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: Index was out of
range. Must be non-negative and less than the size of the collection.
Parameter name: index

Source Error:


Line 187: (e.Item.ItemType ==
System.Web.UI.WebControls.ListItemType.AlternatingItem))
Line 188: {
Line
189: if(applicationPermissionGrid.Items[e.Item.ItemIndex].Cells[6].Text ==
"0")
Line 190: {
Line
191: applicationPermissionGrid.Items[e.Item.ItemIndex].Cells[0].Text =
"NO";


Source File: c:\inetpub\wwwroot\dataviewer\permissionform.aspx.cs Line:
189

Stack Trace:


[ArgumentOutOfRangeException: Index was out of range. Must be non-negative
and less than the size of the collection.
Parameter name: index]
System.Collections.ArrayList.get_Item(Int32 index) +91
System.Web.UI.WebControls.DataGridItemCollection.get_Item(Int32 index)
DataViewer.permissionForm.applicationPermissionGrid_ItemDataBound(Object
sender, DataGridItemEventArgs e) in
c:\inetpub\wwwroot\dataviewer\permissionform.aspx.cs:189
System.Web.UI.WebControls.DataGrid.OnItemDataBound(DataGridItemEventArgs e)
System.Web.UI.WebControls.DataGrid.CreateItem(Int32 itemIndex, Int32
dataSourceIndex, ListItemType itemType, Boolean dataBind, Object dataItem,
DataGridColumn[] columns, TableRowCollection rows, PagedDataSource
pagedDataSource)
System.Web.UI.WebControls.DataGrid.CreateControlHierarchy(Boolean
useDataSource)
System.Web.UI.WebControls.BaseDataList.OnDataBinding(EventArgs e)
System.Web.UI.WebControls.BaseDataList.DataBind()
DataViewer.permissionForm.FillApplicationPermissionGrid() in
c:\inetpub\wwwroot\dataviewer\permissionform.aspx.cs:156
DataViewer.permissionForm.Page_Load(Object sender, EventArgs e) in
c:\inetpub\wwwroot\dataviewer\permissionform.aspx.cs:50
System.Web.UI.Control.OnLoad(EventArgs e)
System.Web.UI.Control.LoadRecursive()
System.Web.UI.Page.ProcessRequestMain()

What do I need to change to correct this?

Thanks,

Dave
 
O

Ollie Riches

David,

you could try the following

.....
if(e.Item.Cells[6].Text == "0")
{
e.Item.Cells[0].Text = "NO";
}
......

HTH

Ollie Riches

kscdavefl said:
When I run the following code:

private void applicationPermissionGrid_ItemDataBound(object sender,
System.Web.UI.WebControls.DataGridItemEventArgs e)
{

if (e.Item.ItemType == System.Web.UI.WebControls.ListItemType.Item ||
(e.Item.ItemType ==
System.Web.UI.WebControls.ListItemType.AlternatingItem))
{
if(applicationPermissionGrid.Items[e.Item.ItemIndex].Cells[6].Text == "0")
{
applicationPermissionGrid.Items[e.Item.ItemIndex].Cells[0].Text = "NO";
}
}

I get the following error:



Index was out of range. Must be non-negative and less than the size of the
collection. 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: Index was out of
range. Must be non-negative and less than the size of the collection.
Parameter name: index

Source Error:


Line 187: (e.Item.ItemType ==
System.Web.UI.WebControls.ListItemType.AlternatingItem))
Line 188: {
Line
189: if(applicationPermissionGrid.Items[e.Item.ItemIndex].Cells[6].Text ==
"0")
Line 190: {
Line
191: applicationPermissionGrid.Items[e.Item.ItemIndex].Cells[0].Text =
"NO";


Source File: c:\inetpub\wwwroot\dataviewer\permissionform.aspx.cs Line:
189

Stack Trace:


[ArgumentOutOfRangeException: Index was out of range. Must be non-negative
and less than the size of the collection.
Parameter name: index]
System.Collections.ArrayList.get_Item(Int32 index) +91
System.Web.UI.WebControls.DataGridItemCollection.get_Item(Int32 index)
DataViewer.permissionForm.applicationPermissionGrid_ItemDataBound(Object
sender, DataGridItemEventArgs e) in
c:\inetpub\wwwroot\dataviewer\permissionform.aspx.cs:189
System.Web.UI.WebControls.DataGrid.OnItemDataBound(DataGridItemEventArgs e)
System.Web.UI.WebControls.DataGrid.CreateItem(Int32 itemIndex, Int32
dataSourceIndex, ListItemType itemType, Boolean dataBind, Object dataItem,
DataGridColumn[] columns, TableRowCollection rows, PagedDataSource
pagedDataSource)
System.Web.UI.WebControls.DataGrid.CreateControlHierarchy(Boolean
useDataSource)
System.Web.UI.WebControls.BaseDataList.OnDataBinding(EventArgs e)
System.Web.UI.WebControls.BaseDataList.DataBind()
DataViewer.permissionForm.FillApplicationPermissionGrid() in
c:\inetpub\wwwroot\dataviewer\permissionform.aspx.cs:156
DataViewer.permissionForm.Page_Load(Object sender, EventArgs e) in
c:\inetpub\wwwroot\dataviewer\permissionform.aspx.cs:50
System.Web.UI.Control.OnLoad(EventArgs e)
System.Web.UI.Control.LoadRecursive()
System.Web.UI.Page.ProcessRequestMain()

What do I need to change to correct this?

Thanks,

Dave
 
G

Guest

Thanks a million .

Ollie Riches said:
David,

you could try the following

.....
if(e.Item.Cells[6].Text == "0")
{
e.Item.Cells[0].Text = "NO";
}
......

HTH

Ollie Riches

kscdavefl said:
When I run the following code:

private void applicationPermissionGrid_ItemDataBound(object sender,
System.Web.UI.WebControls.DataGridItemEventArgs e)
{

if (e.Item.ItemType == System.Web.UI.WebControls.ListItemType.Item ||
(e.Item.ItemType ==
System.Web.UI.WebControls.ListItemType.AlternatingItem))
{
if(applicationPermissionGrid.Items[e.Item.ItemIndex].Cells[6].Text == "0")
{
applicationPermissionGrid.Items[e.Item.ItemIndex].Cells[0].Text = "NO";
}
}

I get the following error:



Index was out of range. Must be non-negative and less than the size of the
collection. 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: Index was out of
range. Must be non-negative and less than the size of the collection.
Parameter name: index

Source Error:


Line 187: (e.Item.ItemType ==
System.Web.UI.WebControls.ListItemType.AlternatingItem))
Line 188: {
Line
189: if(applicationPermissionGrid.Items[e.Item.ItemIndex].Cells[6].Text ==
"0")
Line 190: {
Line
191: applicationPermissionGrid.Items[e.Item.ItemIndex].Cells[0].Text =
"NO";


Source File: c:\inetpub\wwwroot\dataviewer\permissionform.aspx.cs Line:
189

Stack Trace:


[ArgumentOutOfRangeException: Index was out of range. Must be non-negative
and less than the size of the collection.
Parameter name: index]
System.Collections.ArrayList.get_Item(Int32 index) +91
System.Web.UI.WebControls.DataGridItemCollection.get_Item(Int32 index)
DataViewer.permissionForm.applicationPermissionGrid_ItemDataBound(Object
sender, DataGridItemEventArgs e) in
c:\inetpub\wwwroot\dataviewer\permissionform.aspx.cs:189
System.Web.UI.WebControls.DataGrid.OnItemDataBound(DataGridItemEventArgs e)
System.Web.UI.WebControls.DataGrid.CreateItem(Int32 itemIndex, Int32
dataSourceIndex, ListItemType itemType, Boolean dataBind, Object dataItem,
DataGridColumn[] columns, TableRowCollection rows, PagedDataSource
pagedDataSource)
System.Web.UI.WebControls.DataGrid.CreateControlHierarchy(Boolean
useDataSource)
System.Web.UI.WebControls.BaseDataList.OnDataBinding(EventArgs e)
System.Web.UI.WebControls.BaseDataList.DataBind()
DataViewer.permissionForm.FillApplicationPermissionGrid() in
c:\inetpub\wwwroot\dataviewer\permissionform.aspx.cs:156
DataViewer.permissionForm.Page_Load(Object sender, EventArgs e) in
c:\inetpub\wwwroot\dataviewer\permissionform.aspx.cs:50
System.Web.UI.Control.OnLoad(EventArgs e)
System.Web.UI.Control.LoadRecursive()
System.Web.UI.Page.ProcessRequestMain()

What do I need to change to correct this?

Thanks,

Dave
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top