Error with Gridview when i delete the row that have only one row in gridview

 Dear all,

i develop with asp.net 2005 and use gridview and set enable deleteing =true. I can delete record in gridview properly but when gridveiw has only one row and then i'm clike delete button , the error occurs :

 

Server Error in '/it' Application.

Specified argument was out of the range of valid values.
Parameter name: value

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: Specified argument was out of the range of valid values.
Parameter name: value

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: Specified argument was out of the range of valid values.
Parameter name: value]
   System.Web.UI.WebControls.GridView.set_SelectedIndex(Int32 value) +1454263
   System.Web.UI.WebControls.GridView.HandleDeleteCallback(Int32 affectedRows, Exception ex) +354
   System.Web.UI.DataSourceView.Delete(IDictionary keys, IDictionary oldValues, DataSourceViewOperationCallback callback) +123
   System.Web.UI.WebControls.GridView.HandleDelete(GridViewRow row, Int32 rowIndex) +927
   System.Web.UI.WebControls.GridView.HandleEvent(EventArgs e, Boolean causesValidation, String validationGroup) +1155
   System.Web.UI.WebControls.GridView.OnBubbleEvent(Object source, EventArgs e) +95
   System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args) +35
   System.Web.UI.WebControls.GridViewRow.OnBubbleEvent(Object source, EventArgs e) +117
   System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args) +35
   System.Web.UI.WebControls.Button.OnCommand(CommandEventArgs e) +115
   System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +163
   System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +7
   System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +11
   System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +33
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +5102


Pls help me!

 

0
kenghot
1/5/2006 9:55:26 AM
asp.net.presentation-controls 72751 articles. 3 followers. Follow

5 Replies
1371 Views

Similar Articles

[PageSpeed] 17

Do you have any code to support your page. Looks like framework is trying to set the selected index after deleting the row

Bug [MCSD]
0
Bug_Bugger
1/5/2006 1:53:20 PM

i didn't code at all. Just created "SqlDatasource" and "Gridview" controls on page.

<asp:SqlDataSource ID="sqlSo" runat="server" ConnectionString="<%$ ConnectionStrings:cnDc %>" SelectCommand="SELECT df_soheader.so_id, df_soheader.del_flag, df_soheader.so_type, df_soheader.dept_id, df_carton.carton_name, df_soheader.so_date, df_sotrans.carton_id, df_sotrans.so_item, df_sotrans.cabin_dim_id, df_sotrans.date_in, df_sotrans.date_due, df_so_status.so_status_name, df_soheader.so_status FROM df_soheader INNER JOIN df_sotrans ON df_soheader.so_id = df_sotrans.so_id INNER JOIN df_carton ON df_sotrans.carton_id = df_carton.carton_id LEFT OUTER JOIN df_so_status ON df_soheader.so_status = df_so_status.so_status_id WHERE (df_soheader.so_id = @so_id)" DeleteCommand="DELETE FROM df_sotrans where so_id = @so_id and so_item = @so_item">

<SelectParameters>

<asp:ControlParameter ControlID="txbSoNo" Name="so_id" PropertyName="Text" />

</SelectParameters>

<DeleteParameters>

<asp:Parameter Name="so_id" />

<asp:Parameter Name="so_item" Type="Int64" />

</DeleteParameters>

</asp:SqlDataSource>

 

<asp:GridView ID="gvSo" runat="server" AutoGenerateColumns="False" EmptyDataText="Data is not found" BackColor="White" BorderColor="#DEDFDE" BorderStyle="None" BorderWidth="1px" CellPadding="4" CssClass="stkfont" ForeColor="Black" GridLines="Vertical" Width="100%" DataSourceID="sqlSo" DataKeyNames="so_id,so_item">

<FooterStyle BackColor="#CCCC99" />

<Columns>

<asp:TemplateField HeaderText="Action" ShowHeader="False">

<EditItemTemplate>

<asp:Button ID="Button1" runat="server" CausesValidation="True" CommandName="Update"

Text="Update" />&nbsp;<asp:Button ID="Button2" runat="server" CausesValidation="False"

CommandName="Cancel" Text="Cancel" />

</EditItemTemplate>

<ItemStyle Width="100px" />

<ItemTemplate>

<asp:Button ID="Button1" runat="server" CausesValidation="False" CommandName="Edit"

Text="Edit" />&nbsp;<asp:Button ID="Button2" runat="server" CausesValidation="False"

CommandName="Delete" OnClientClick="return confirm('Do you want to delete reccord ?')"

Text="Delete" />

</ItemTemplate>

</asp:TemplateField>

<asp:BoundField DataField="carton_id" HeaderText="Carton Code.">

<ItemStyle Width="100px" />

</asp:BoundField>

<asp:BoundField DataField="carton_name" HeaderText="Description" HtmlEncode="False">

<ControlStyle Width="600px" />

<ItemStyle Width="300px" />

</asp:BoundField>

<asp:BoundField DataField="date_in" HeaderText="Date In" DataFormatString=" {0:dd/MM/yyyy} " HtmlEncode="False">

<ItemStyle Width="100px" />

</asp:BoundField>

<asp:BoundField DataField="date_due" HeaderText="Date Due" DataFormatString=" {0:dd/MM/yyyy} " HtmlEncode="False">

<ItemStyle Width="100px" />

</asp:BoundField>

<asp:BoundField DataField="cabin_dim_id" HeaderText="Location" />

</Columns>

<RowStyle BackColor="#F7F7DE" />

<SelectedRowStyle BackColor="#CE5D5A" Font-Bold="True" ForeColor="White" />

<PagerStyle BackColor="#F7F7DE" ForeColor="Black" HorizontalAlign="Right" />

<HeaderStyle BackColor="#6B696B" Font-Bold="True" ForeColor="White" />

<AlternatingRowStyle BackColor="White" />

</asp:GridView>

*--------------

best regrads,

Keng

0
kenghot
1/6/2006 4:24:30 AM
Hmm, i've tried your code - all i am getting is 'Data is not found'
message shown in a control but no error is generated. Is there anyting else on your page?


Bug [MCSD]
0
Bug_Bugger
1/6/2006 1:15:48 PM
I have run into this before and it seem to be an intermitent bug with the gridview. The fix I used is to enable selecting on the grid then set the column visiblility to false
0
dcrowder
7/28/2006 4:49:00 PM

This may happen if the number of rows deleted in database is more than one. For example if there is a trigger associated for the delete operation that updates some other data, then the total number of affected rows is more than one, lets say it is 2 rows. Gridview now tries to set the index to two rows above the item deleted. But as there are no items in the grid it fails.

0
mvbgupta
12/13/2007 10:06:10 PM
Reply:

Similar Artilces:

Add new controls to a gridview row; when editing that row using the edit row feature in the gridview control.
Hi all  I have a questions that looks hard / complex to me, and i know you can help me in this. Q {  I have row in a Gridview and i have an edit option to it. I press the edit button, to edit the values in that row and update data all the way back to the database. Now when i press the edit button, i want a drop down list to be displayed that contain values for a particular field in my grid view. (for now only plain text boxes appear.) } I hope you understand my question, all i need to do is replace the text box controls with a dropdown list when i am editing a row in ...

Data Controls insert rows into gridview then insert rows from gridview into SQL Table
Hello there, I'm still new at performing miracles with code . Currently I am having trouble with my latest coding adventure I have a web application which records jobs and labour assigned to jobs. The issue in particular I'm having is the way in which labour is to be assigned. I want to use standard controls (Textbox, Dropdownlist) to record the values into a gridview (ie,put multiple rows into the gridview using the controls). Then, when all the inserting is complete, the user clicks a submit button to insert all the rows from the gridview into a database table. The reason for...

How can i copy one row or more from 1 gridview to the same gridview and other gridview ?
Hi All,      Hi, i am using visual web developer 2008 express, i need to copy some rows in a grid view to the same gridview and other gridview help me with the code when press copy. Thanks. My code : code Behind: using System; using System.Collections; using System.Configuration; using System.Data; using System.Linq; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.HtmlControls; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Xml.Linq; using System.Data.SqlClient; using System.T...

How to delete row from GridView control
Hello,  I am working on an ASP.NET 2.0 app, and I am trying to wire up a "Delete" button to a gridview control on a form. Here is the code for the ASP :  <asp:GridView ID="gvInConditions" runat="server" AutoGenerateColumns="true" OnRowDeleting="gvInConditions_RowDeleting" DataKeyNames="Condition_ID" >         <Columns>                <asp:CommandField ButtonType="Button" SelectText=&...

How can i give alert box when one row from gridview is deleted (gridview is inside a updatepane)....
How can i give alert box when one row from gridview is deleted (gridview is inside a updatepane)........ Please help me...... Hi There, Guess this is what you trying to do: void GridView1_RowDeleting(Object sender, GridViewDeleteEventArgs e) { // Do whatever to delete your record   //// Build your alert scriptStringBuilder sbScript = new StringBuilder(); sbScript.Append("<script language='JavaScript' type='text/javascript'>");sbScript.Append("alert('Sucessfully delete 1 record!')"); sbScript.Append("<"); sbScri...

How can i give alert box when one row from gridview is deleted (gridview is inside a updatepanel)........
How can i give alert box when one row from gridview is deleted (gridview is inside a updatepanel)........ Please help me......  Hi,try to:1. Hook up the RowDeleted event of the GridView.2. Inject the following JavaScript using the ScriptManager.RegisterStartupScript method: (function() { var fn = function() { alert('Row Deleted!'); Sys.Application.remove_load(fn); } Sys.Application.add_load(fn); })();  Alessandro Gallo | Blog | My book: ASP.NET AJAX In Action I can't understand that....how i give this? from where i...

GridView.Rows.Count after deleting rows
How do I get the count of GridView's data rows that is displaying?If I use GridView.Rows.Count, after deleting a row, it won't change - as same as before deleting, and nor do GridView.DataKeys.Count.  My blog (zh-CN)Be and awear of who you are. Most likely, you'll have to re-bind the data after the deletion. If so, go ahead and retrieve your count during the DataBound event, then you'll know you're retrieving an accurate count.Thanks, EdMicrosoft MVP - ASP/ASP.NET Yes, that's the easiest way to do this.I finally chose another way: in DataBound event, record the count, and in&nb...

Selecting a gridview row and keeping the last selected row in a gridview highlighted after mouse moves over a new row.
What is the best way to show a gridview row highlighted once selected and keep it highlighted once the mouse moves over a different row? Thanks, Steve hi,you can use <SelectedRowStyle BackColor="#008A8C" Font-Bold="True" ForeColor="#FFFFFF" /> plz let me know if i misunderstood you Thanks for your help. One problem; however, is that after the row has been selected and I check the "grid.SelectedIndex" it has a value of -1 and not the index of the row that was selected on the grid. What do you recommend? Thanks, Steve hi, sorry i din...

How to delete controls in GridView when the delete button in a row is clicked
Hi,   I am having issues with my gridview.....i added 2 dropdown and 2 compare validators....whenever i delete a row though......the dropdown and compare validators are becoming null........thus when i click a button, it is still validating.............anyway to delete this when i click the delete button or even handle?   Please help.  ...

Adding data to gridview from two textboxes and then deleting them by delete button in each gridview row.
Hi, my app has 2 textboxes if i enter data and click add button they shud be added to gridview with 2 columns ex: custid from txtbox1 ... and custname frm txtbox2 added to gridview   with columns custid and custname then    foreach row a delete button shud appear in gridview and on clicking it shud delete the row can any one send me code for dis   thanks in advance Hi, In your Button Click Event write this code. DataControlField dCusId; DataControlField dCustName; dCusId.HeaderText = textbox1.text; dCustName.HeaderText = textbox2.text Gridv...

Adding row (one at a time) in gridview on a button click. And cells of added row should contain controls like DROPDOWN LIST or TEXT BOX.
Dear Friends, I am in great need for the solution/hints/guidance of my requirement, if anyone can help with.  Let me explain what I need."I need a Gridview control on a webpage having following 5 columns/fields.     Column 1: It just has a "+" button in its header only (other cells for this column is empty)    Column 2: The Column header here is "FIELD" and  it should contain dropdown list (which is populated from some database)    Column 3: The Column header here is "Operator" and  it should ...

gridview show mulitple rows in one row
I want to show an overview of users, with all classes they have attended and from which year to which year.My userdata is in tblUsers, the info on classes they have been in is stored in tblClassesEach user may have attended 0 to 12 classes.My SQL query returns a row with userdata for each class a user has attended (which is supposed to work like this).Now in my gridview I want to show 1 row PER user and in that same row I want to show all classes that were attended...How can I achieve that?So I might well have 10 rows returned for user Peter, but I want to have one row in my gridview that sh...

GridView.Rows(Column=ID_PK) to GridView.Rows(Column=DropDownListTeamplteField)
Hi Guys,I wonder how I can assign the PrimaryKey in each GridView Row to the template field in the same row. whereas the template field is filled with a dropdownlist thatshould show the values for retrieved in a different table through the GridView Row primary key (which serves as the SELECT parameter to get these values) The GridView looks like this:<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataKeyNames="C_ID" DataSourceID="GetC_IDs"> <Columns> <asp:BoundField D...

Gridview.Rows.Count not incremented after call to GridView.Rows.AddAt()
Hi All, I've got a grid view that was created from a static DataTable.  I then wish to add a row to the gridview.   However the GridView.Rows.Count does not increment after I add a row to the underlying Table extracted as gv.Controls[0] as Table.  I need the gridview to maintain the correct number of rows because a post processing routine then accesses the newly addrows throught the gridview.Rows[i].Cells[j] calls. Thanks, cr  static protected void AddRow(GridView gv, out string sOut) { Table t = gv.Controls[0] as Table; GridViewRow r = new GridViewRow...

Web resources about - Error with Gridview when i delete the row that have only one row in gridview - asp.net.presentation-controls

GridView SelectedItem Binding Gotcha in WinRT
Last night when I was doing some WinRT hacking I was trying to setup databinding to the selected item in the GridView control and I ran into ...

CNW Group
Home Services Beyond the Wire About CNW Financials Webcasts Events My CNW All News Releases Advanced Search Gridview Latest News Releases All ...

CNW Group
... Services Beyond the Wire About CNW my CNW CNW Access CNW Directories Financials Webcasts Events my CNW All News Releases Advanced Search Gridview ...

CNW Group
Home Services Beyond the Wire About CNW Financials Webcasts Events My CNW All News Releases Add a Filter Gridview Latest News Releases All Today ...

New CmdLets of Powershell 2.0
New CmdLets of Powershell 2.0

Price Drop: Softbox
... objects- create product reflection- changing the background with something more interestingUse it as:- softbox- honeycomb softbox- gridview ...

Profile.aspx: ASP Alliance
.NET,ASP,ASP.NET,SQL,XML,HTML,ADO,ADO.NET,JavaScript,JScript,CSharp,VBScript and VB tutorials from AspAlliance.

Quick Answers - CodeProject
Questions - Free source code and tutorials for Software developers and Architects.; Updated: 25 Oct 2012

DotNetKicks.com - Upcoming stories
DotNetKicks.com is a community based news site edited by our members. It specialises in .NET development techniques, technologies and tools including ...

View Features - ExtendASP
Call 847-681-9827 or Request a Demo View Features Testimonials Pricing About Us Coming Soon ExtendASP exposes every feature, more than any other ...

Resources last updated: 12/11/2015 10:50:54 AM