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.
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.
Parameter name: value
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 |
![]() |
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 |
![]() |
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" /> <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" /> <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 |
![]() |
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 |
![]() |
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 |
![]() |
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 |
![]() |