Hallo Thomas,

ich habe in meinem Warenkorb auch schon mal so ein Problem gehabt. Könnte sein,
dass es daran liegt: Wenn Du aus dem Warenkorb bzw. aus dem DataTable einen
Eintrag i löschst, dann ist der (i + 1). Eintrag um eine Position nach unten
gerutscht. Ich habe das dann so gelöst, dass ich (falls DataRow i wirklich auch
gelöscht wird) im if-Block das i um eins verringert habe (i--).

Vielleicht hilft's ja. Gruß,

Anh Tu

Thomas Beckert - SitePoint GbR <> wrote:
> Hi Liste,
> 
> ich habe in meiner Session eine DataTable, aus der ich gerne einen eintrag
> löschen würde. das wollte ich mit folgender funktion machen: 
> Sub DeleteArtikel(ByVal id As Integer)
> 
> Dim objDataTable As DataTable = CType(Session("warenkorb"), DataTable)
> 
> Dim i As Integer
> 
> For i = 0 To objDataTable.Rows.Count - 1
> 
> If CInt(objDataTable.Rows(i)("id")) = id Then
> 
> objDataTable.Rows.RemoveAt(i)
> 
> End If
> 
> Next
> 
> objDataTable.AcceptChanges()
> 
> If objDataTable.Rows.Count = 0 Then
> 
> Response.Redirect("warenkorb.aspx")
> 
> Else
> 
> Datenlesen()
> 
> End If
> 
> End Sub
> 
> 
> jedoch bekomme ich danach immer folgende exception:
> 
> There is no row at position 2.
> 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.IndexOutOfRangeException: There is no row at
> position 2. 
> 
> 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:
> 
> 
> [IndexOutOfRangeException: There is no row at position 2.]
>    System.Data.DataRowCollection.get_Item(Int32 index) +63
>    Vinerie.Warenkorb.DeleteArtikel(Int32 id) +102
>    Vinerie.Warenkorb.ibtnDelete_Click(Object sender, ImageClickEventArgs e)
> +40
>    System.Web.UI.WebControls.ImageButton.OnClick(ImageClickEventArgs e) +109
>   
>
System.Web.UI.WebControls.ImageButton.System.Web.UI.IPostBackEventHandler.RaiseP
ostBackEvent(String
> eventArgument) +69
>    System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler
> sourceControl, String eventArgument) +18
>    System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +33
>    System.Web.UI.Page.ProcessRequestMain() +1277
> 
> 
> 
> -----------------------------------------------
> SitePoint GbR
> Thomas Beckert
> Vorstadtstr.57
> 66117 Saarbrücken
> 
> Tel.: +49 681 / 9 47 26 27
> Fax.: +49 681 / 9 47 26 28
> 
> www.sitepoint.de
> ----------------------------------------------
> 
> 
> _______________________________________________
> Asp.net Mailingliste, Postings senden an:
> Asp.net@glengamoi.com
> An-/Abmeldung und Suchfunktion unter:
> http://www.glengamoi.com/mailman/listinfo/asp.net

_______________________________________________
Asp.net Mailingliste, Postings senden an:
Asp.net@glengamoi.com
An-/Abmeldung und Suchfunktion unter:
http://www.glengamoi.com/mailman/listinfo/asp.net

Antwort per Email an