Deleting row from GridView causes ArgumentOutOfRangeException during System.Web.UI.WebControls.GridV

L

loga123

Hi All,

I am using Link Button for DELETE on the gridview. When I click on
DELETE link, I get the ArgumentOutOfRangeException. But...it deletes
the record from table in the database.
On Gridview_rowdatabound, I am dynamically building hyperlink control
based on the values in the other fields. Here is my code for
Gridview_rowdatabound. It does work sometimes though.


Protected Sub dgQuestions_RowDataBound(ByVal sender As Object, ByVal e
As System.Web.UI.WebControls.GridViewRowEventArgs) Handles
dgQuestions.RowDataBound

If e.Row.RowType = DataControlRowType.DataRow Then

Dim hLnk As HyperLink = CType(e.Row.Cells(3).Controls(0),
HyperLink)

Dim iCID As String
iCID = drpClasses.SelectedValue


Dim iQSeq As Integer
iQ = cint(e.Row.Cells(1).Text)
hLnk.NavigateUrl = "ShowDetails.aspx?CID=" & iCID

End If
End Sub

Please, see Stack Trace below. Any ideas anyone?

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)
+1454311
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.LinkButton.OnCommand(CommandEventArgs e)
+115
System.Web.UI.WebControls.LinkButton.RaisePostBackEvent(String
eventArgument) +163

System.Web.UI.WebControls.LinkButton.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)
+174
System.Web.UI.Page.ProcessRequestMain(Boolean
includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
+5102
 
J

John Prado

Use a template column and a generic hyperlink button to achieve your
ShowDetails goal.

Here is the cause of your problems:

System.Web.UI.WebControls.GridView.HandleDeleteCallback(Int32
affectedRows, Exception ex)

You can create a new hyperlink in real time and add it to your cell.

e.Row.Cells(3).Controls.Add(hyperlink) in ex.
Hi All,

I am using Link Button for DELETE on the gridview. When I click on
DELETE link, I get the ArgumentOutOfRangeException. But...it deletes
the record from table in the database.
On Gridview_rowdatabound, I am dynamically building hyperlink control
based on the values in the other fields. Here is my code for
Gridview_rowdatabound. It does work sometimes though.


Protected Sub dgQuestions_RowDataBound(ByVal sender As Object, ByVal e
As System.Web.UI.WebControls.GridViewRowEventArgs) Handles
dgQuestions.RowDataBound

If e.Row.RowType = DataControlRowType.DataRow Then

Dim hLnk As HyperLink = CType(e.Row.Cells(3).Controls(0),
HyperLink)

Dim iCID As String
iCID = drpClasses.SelectedValue


Dim iQSeq As Integer
iQ = cint(e.Row.Cells(1).Text)
hLnk.NavigateUrl = "ShowDetails.aspx?CID=" & iCID

End If
End Sub

Please, see Stack Trace below. Any ideas anyone?

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)
+1454311
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.LinkButton.OnCommand(CommandEventArgs e)
+115
System.Web.UI.WebControls.LinkButton.RaisePostBackEvent(String
eventArgument) +163

System.Web.UI.WebControls.LinkButton.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)
+174
System.Web.UI.Page.ProcessRequestMain(Boolean
includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
+5102
 
L

loga123

Hi John,

Thanks for your reply.
I tried your suggestion...but still have the same problem. I am not
sure why I have such problem.
Any help is greatly appreciated.

Thanks in advance.


John said:
Use a template column and a generic hyperlink button to achieve your
ShowDetails goal.

Here is the cause of your problems:

System.Web.UI.WebControls.GridView.HandleDeleteCallback(Int32
affectedRows, Exception ex)

You can create a new hyperlink in real time and add it to your cell.

e.Row.Cells(3).Controls.Add(hyperlink) in ex.
Hi All,

I am using Link Button for DELETE on the gridview. When I click on
DELETE link, I get the ArgumentOutOfRangeException. But...it deletes
the record from table in the database.
On Gridview_rowdatabound, I am dynamically building hyperlink control
based on the values in the other fields. Here is my code for
Gridview_rowdatabound. It does work sometimes though.


Protected Sub dgQuestions_RowDataBound(ByVal sender As Object, ByVal e
As System.Web.UI.WebControls.GridViewRowEventArgs) Handles
dgQuestions.RowDataBound

If e.Row.RowType = DataControlRowType.DataRow Then

Dim hLnk As HyperLink = CType(e.Row.Cells(3).Controls(0),
HyperLink)

Dim iCID As String
iCID = drpClasses.SelectedValue


Dim iQSeq As Integer
iQ = cint(e.Row.Cells(1).Text)
hLnk.NavigateUrl = "ShowDetails.aspx?CID=" & iCID

End If
End Sub

Please, see Stack Trace below. Any ideas anyone?

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)
+1454311
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.LinkButton.OnCommand(CommandEventArgs e)
+115
System.Web.UI.WebControls.LinkButton.RaisePostBackEvent(String
eventArgument) +163

System.Web.UI.WebControls.LinkButton.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)
+174
System.Web.UI.Page.ProcessRequestMain(Boolean
includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
+5102
 

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

Members online

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,020
Latest member
GenesisGai

Latest Threads

Top