bonjour,
J'essai de faire afficher un confirmation box quand je click sur delete dans le gridview. J'ai chercher sur internet et j'ai trouvé plein de solution mais qui ne fonctionne pas pour mon exemple.
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
31
32
33
34
35
36 <asp:GridView ID="LstFluxGvw" runat="server" EnableViewState="False" CellPadding="4" ForeColor="#333333" GridLines="Vertical" OnSelectedIndexChanged="SelectedIndexChangedLstFluxGvw" OnRowEditing="AffichIndexChangedGvw" OnRowDeleting="Delete" Width="741px" AutoGenerateColumns="False" Height="165px" AutoGenerateSelectButton="False" EnableTheming="True"> <FooterStyle BackColor="#1C5E55" Font-Bold="True" ForeColor="White" HorizontalAlign="Center" /> <Columns> <asp:HyperLinkField headertext="Fichier" datatextfield="nomFlux" datanavigateurlformatstring="fluxRSS.aspx?XML={0}" datanavigateurlfields="nomFlux" /> <asp:BoundField DataField="title" HeaderText="Titre" /> <asp:BoundField DataField="link" HeaderText="Lien" /> <asp:CommandField HeaderText="Select" ShowSelectButton="True" ButtonType="Button"/> <asp:CommandField DeleteText="Supprimer" HeaderText="Delete" ShowDeleteButton="True" /> <asp:CommandField HeaderText="Affichage" EditText="Voir" ShowEditButton="True" /> </Columns> .... protected void Delete(object sender,GridViewDeleteEventArgs e) { XmlDocument lstRssXmlDoc = new XmlDocument(); lstRssXmlDoc.Load(Server.MapPath("lstRss.xml")); XmlNodeList fluxNL = lstRssXmlDoc.DocumentElement.ChildNodes; XmlNode fluxN = fluxNL.Item(e.RowIndex); string stringpath = fluxN["nomFlux"].InnerText; string fichierSupp = Server.MapPath(stringpath); FileInfo RssFile = new FileInfo(fichierSupp); //si le fichier existe if (RssFile.Exists) { FileInfo DeleteFile = new FileInfo(fichierSupp); DeleteFile.Delete(); fluxN.ParentNode.RemoveChild(fluxN); lstRssXmlDoc.Save(Server.MapPath("lstRss.xml")); } }
Dans ce que j'ai vu sur internet, il changeait le commandfield en linkbutton.
Je l'ai fait mais le pb ce que quand je click sur delete, il ne se passe rien :
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52 <Columns> <asp:HyperLinkField headertext="Fichier" datatextfield="nomFlux" datanavigateurlformatstring="fluxRSS.aspx?XML={0}" datanavigateurlfields="nomFlux" /> <asp:BoundField DataField="title" HeaderText="Titre" /> <asp:BoundField DataField="link" HeaderText="Lien" /> <asp:CommandField HeaderText="Select" ShowSelectButton="True"/> <asp:TemplateField HeaderText="Delete" > <ItemTemplate> <asp:Button ID="ibDelete" runat="server" Text="suppr" CausesValidation="false" CommandName="Delete" /> </ItemTemplate> </asp:TemplateField> <asp:CommandField HeaderText="Affichage" EditText="Voir" ShowEditButton="True" /> </Columns> protected void gridOverview_OnRowDataBound(object sender, GridViewRowEventArgs e) //Add delete msgbox to each row containing field //information to identify the row { if (e.Row.RowType == DataControlRowType.DataRow) { // reference the Delete Button Button btn = (Button)e.Row.FindControl("ibDelete"); //btn.Attributes.Add("onclick", "javascript:if(confirm('Etes vous sûr de vouloir supprimer?')== false) return false;"); btn.Attributes.Add("onclick","javascript:return + confirm('Are you sure about deleting " + DataBinder.Eval(e.Row.DataItem, "nomFlux") + "?');"); } } protected void Delete(object sender,GridViewDeleteEventArgs e) { XmlDocument lstRssXmlDoc = new XmlDocument(); lstRssXmlDoc.Load(Server.MapPath("lstRss.xml")); XmlNodeList fluxNL = lstRssXmlDoc.DocumentElement.ChildNodes; XmlNode fluxN = fluxNL.Item(e.RowIndex); string stringpath = fluxN["nomFlux"].InnerText; string fichierSupp = Server.MapPath(stringpath); FileInfo RssFile = new FileInfo(fichierSupp); //si le fichier existe if (RssFile.Exists) { FileInfo DeleteFile = new FileInfo(fichierSupp); DeleteFile.Delete(); fluxN.ParentNode.RemoveChild(fluxN); lstRssXmlDoc.Save(Server.MapPath("lstRss.xml")); } }
Quand je click sur supprimer j'ai bien le confirmation box mais la procédure delete n'est pas éxécuter.
Partager