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

Discussion in 'ASP .Net' started by loga123, Jun 28, 2006.

  1. loga123

    loga123 Guest

    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
     
    loga123, Jun 28, 2006
    #1
    1. Advertising

  2. loga123

    John Prado Guest

    Re: Deleting row from GridView causes ArgumentOutOfRangeExceptionduring System.Web.UI.WebControls.GridView.set_SelectedIndex(Int32 value)

    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.

    loga123 wrote:
    > 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
    >
     
    John Prado, Jun 28, 2006
    #2
    1. Advertising

  3. loga123

    loga123 Guest

    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 Prado wrote:
    > 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.
    >
    > loga123 wrote:
    > > 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
    > >
     
    loga123, Jun 28, 2006
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?Utf-8?B?SG96aQ==?=
    Replies:
    1
    Views:
    6,966
    Ken Cox [Microsoft MVP]
    Jun 2, 2004
  2. hari
    Replies:
    3
    Views:
    12,549
    Vimal
    Nov 15, 2006
  3. J055
    Replies:
    4
    Views:
    7,912
    Steven Cheng[MSFT]
    Nov 14, 2007
  4. JB

    Gridv

    JB, Oct 3, 2009, in forum: ASP .Net
    Replies:
    1
    Views:
    351
    Alexey Smirnov
    Oct 5, 2009
  5. leezard

    System.ArgumentOutOfRangeException

    leezard, Aug 20, 2003, in forum: ASP .Net Datagrid Control
    Replies:
    1
    Views:
    135
    leezard
    Aug 20, 2003
Loading...

Share This Page