Bonjour ,
Je souhaite supprimer un row de ma gridview Grace a un control checkbox et un boutton supprimer , mais j'ai le message d'erreur suivant:
Voila le code asp :L'index était hors limites. Il ne doit pas être négatif et doit être inférieur à la taille de la collection. Nom du paramètre : index
et voila le code que j'ai mis dans le boutton supprimer ( en vb ) :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30 <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataSourceID="SqlDataSource1" ShowFooter="true" > <Columns> <asp:TemplateField> <ItemTemplate> <asp:CheckBox ID="chkSelect" runat="server" /> </ItemTemplate> </asp:TemplateField> <asp:BoundField DataField="Id" HeaderText="Id" SortExpression="Id" InsertVisible="False" ReadOnly="True" /> <asp:BoundField DataField="Nom" HeaderText="Nom" SortExpression="Nom" /> </Columns> </asp:GridView> <asp:SqlDataSource ID="SqlDataSource1" runat="server" SelectCommand="SELECT [Id], [Nom] FROM [Produit]" DeleteCommand="DELETE FROM produit WHERE [id] = @id" ConnectionString="<%$ ConnectionStrings:super_marcheConnectionString %>"> <DeleteParameters> <asp: Parameter Name="id" /> </DeleteParameters> </asp:SqlDataSource>
Merci d'avance
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26 ' Looping through all the rows in the GridView For Each row As GridViewRow In GridView1.Rows Dim checkbox As CheckBox = CType(row.FindControl("chkSelect"), CheckBox) 'Check if the checkbox is checked. 'value in the HtmlInputCheckBox's Value property is set as the //value of the delete command's parameter. If checkbox.Checked Then ' Retreive the Employee ID Dim id As Integer = Convert.ToInt32(GridView1.DataKeys(row.RowState).Value) ' Pass the value of the selected Employye ID to the Delete //command. SqlDataSource1.DeleteParameters("Id").DefaultValue = id.ToString() SqlDataSource1.Delete() End If Next row![]()
Partager