473,473 Members | 1,754 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Stupid undocumented grid indexing . . .

Hi

I have a grid, I want to delete a row.

The relevant code is something like

private void dGridErrorLog_DeleteCommand(object source,
System.Web.UI.WebControls.DataGridCommandEventArgs e)
{

// delete the row
nxCmdDeleteErrorLogItem.Parameters["@LogID"].Value =
dGridErrorLog.DataKeys[e.Item.ItemIndex];
nxConnection.Open();
nxCmdDeleteErrorLogItem.ExecuteNonQuery();
nxConnection.Close();

// rebind the grid:
nxConnection.Open();
nxDataAdapterErrorLog.Fill(nxDataAdapterErrorLog_D ataSet, "errorlog");
dGridErrorLog.DataSource = nxDataAdapterErrorLog_DataSet;
dGridErrorLog.DataMember = "errorlog";
dGridErrorLog.DataBind();
nxConnection.Close();

}

The grid has four rows, which I can see return values for e.Item.ItemIndex
of 0, 1, 2, 3 depending on which row I click on. But calculating

dGridErrorLog.DataKeys[e.Item.ItemIndex];

gives me errors like

<<

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 347: private void dGridErrorLog_DeleteCommand(object source,
System.Web.UI.WebControls.DataGridCommandEventArgs e)
Line 348: {
Line 349: lblTest.Text =
dGridErrorLog.DataKeys[e.Item.ItemIndex].ToString();

Source File:
e:\inetpub\wwwroot\Mywebinterface_nexusdb\admin\vi ewerrorlog.aspx.cs
Line: 349

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.DataKeyCollection.get_It em(Int32 index) +10

MyWebInterface_NexusDB.Admin.ViewErrorLog.dGridErr orLog_DeleteCommand(Object
source, DataGridCommandEventArgs e) in
e:\inetpub\wwwroot\Mywebinterface_nexusdb\admin\vi ewerrorlog.aspx.cs:349

System.Web.UI.WebControls.DataGrid.OnDeleteCommand (DataGridCommandEventArgs
e) +110
System.Web.UI.WebControls.DataGrid.OnBubbleEvent(O bject source, EventArgs
e) +589
System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args) +26
System.Web.UI.WebControls.DataGridItem.OnBubbleEve nt(Object source,
EventArgs e) +106
System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args) +26
System.Web.UI.WebControls.LinkButton.OnCommand(Com mandEventArgs e) +121

System.Web.UI.WebControls.LinkButton.System.Web.UI .IPostBackEventHandler.Rai
sePostBackEvent(String eventArgument) +115
System.Web.UI.Page.RaisePostBackEvent(IPostBackEve ntHandler
sourceControl, String eventArgument) +18
System.Web.UI.Page.RaisePostBackEvent(NameValueCol lection postData) +138
System.Web.UI.Page.ProcessRequestMain() +1277


Any suggestions?

Thanks!

Lauchlan M

Nov 18 '05 #1
1 851
"Lauchlan M" <LM********@Hotmail.com> wrote in message
news:uE**************@TK2MSFTNGP11.phx.gbl...
Hi

I have a grid, I want to delete a row.

The relevant code is something like

private void dGridErrorLog_DeleteCommand(object source,
System.Web.UI.WebControls.DataGridCommandEventArgs e)
{

// delete the row
nxCmdDeleteErrorLogItem.Parameters["@LogID"].Value =
dGridErrorLog.DataKeys[e.Item.ItemIndex];
nxConnection.Open();
nxCmdDeleteErrorLogItem.ExecuteNonQuery();
nxConnection.Close();

// rebind the grid:
nxConnection.Open();
nxDataAdapterErrorLog.Fill(nxDataAdapterErrorLog_D ataSet, "errorlog");
dGridErrorLog.DataSource = nxDataAdapterErrorLog_DataSet;
dGridErrorLog.DataMember = "errorlog";
dGridErrorLog.DataBind();
nxConnection.Close();

}


Should you be clearing nxDataAdapterErrorLog_DataSet before filling it
again?
--
John Saunders
jo**************@hotmail.com
Nov 18 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Joshua Beall | last post by:
Hi All, I've seen many references to the $_SERVER variable, which is set to the string 'on' when the client is connected via HTTPS rather than regular HTTP. However, I have been unable to find...
21
by: Hilde Roth | last post by:
This may have been asked before but I can't find it. If I have a rectangular list of lists, say, l = ,,], is there a handy syntax for retrieving the ith item of every sublist? I know about for i...
1
by: C++ Shark | last post by:
Hi, the following doesn't compile. #include<iostream> #include<vector> using namespace std; class tile_type { vector<vector<int> > grid(3, vector<int> (3)); public: };
108
by: Bryan Olson | last post by:
The Python slice type has one method 'indices', and reportedly: This method takes a single integer argument /length/ and computes information about the extended slice that the slice object would...
19
by: Sput | last post by:
I am thoroughly frustrated with these seemingly unchangable settings in C#. For example, fetching data from database sorted by date returns wrong order (would be correct if I was using american...
0
by: Workgroups | last post by:
Not sure the best way to go about making this: I have 3 user defineable values - Width, Height, and Size. These values need to define a "grid" of some kind in the following manner: The Width is...
7
by: Ryan | last post by:
I have a bit of a problem with regards an indexing strategy. Well, basically there is no indexing strategy on a set of data I have at work. Now, I didn't create the design as I would have allowed...
2
by: =?ISO-8859-1?Q?Marco_K=F6rner?= | last post by:
Hello, I'm working on mapping the car's environment by updating an occupancy grid. An occupancy grid dicretizes the 3D space in small grid elements (voxels). A grid element contains informations...
2
by: =?Utf-8?B?SmVycnkgQw==?= | last post by:
I have a server 2008 IIS 7.0 with indexing service installed. I have created the catalog and have a test page using these posts:...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.