Thanks for answering! I've got everything like you said I should and I've also deleted that silly comma there!?
But now when I click on 'save' I'm redirected to the confirmation page (without an error message) although the data has not been saved in the database ... It's like I said before, when I add fup1 to the InsertCommand then the data is not saved anymore ...
I also had both an ButtonClick and an ItemInserting event, that seemed to cause some problems too ... I've put everything in thie ItemInserting event now.
basheerkal
Star
10672 Points
2426 Posts
Re: How to save the filename from an FileUpload control on a FormView?
Mar 21, 2012 02:22 PM|LINK
Please show me your HTML and code. Let me test it.
(Talk less..Work more)
Subliminal V...
Member
604 Points
195 Posts
Re: How to save the filename from an FileUpload control on a FormView?
Mar 21, 2012 02:44 PM|LINK
That's a lot though ... the name of the FileUpload control is 'File1' and the name of the parameter is 'fup1'
Here's the code:
Partial Class Content_default Inherits System.Web.UI.Page Protected Sub frmDemande_ItemInserted(sender As Object, e As System.Web.UI.WebControls.FormViewInsertedEventArgs) Handles frmDemande.ItemInserted Response.Redirect("DemSaisie.aspx") End Sub Protected Sub Button1_Click(sender As Object, e As System.EventArgs) Dim fUpload1, fUpload2, fUpload3 As FileUpload Dim savePath1, savePath2, savePath3, newFileName As String Dim saveDir As String = "\Uploads\" Dim appPath As String = Request.PhysicalApplicationPath fUpload1 = frmDemande.FindControl("File1") fUpload2 = frmDemande.FindControl("File2") fUpload3 = frmDemande.FindControl("File3") If fUpload1.HasFile Then newFileName = Session("MyLogin") + Server.HtmlEncode(fUpload1.FileName) savePath1 = appPath + saveDir + newFileName fUpload1.SaveAs(savePath1) End If If fUpload2.HasFile Then newFileName = Session("MyLogin") + Server.HtmlEncode(fUpload2.FileName) savePath2 = appPath + saveDir + Server.HtmlEncode(fUpload2.FileName) fUpload2.SaveAs(savePath2) End If If fUpload3.HasFile Then newFileName = Session("MyLogin") + Server.HtmlEncode(fUpload3.FileName) savePath3 = appPath + saveDir + Server.HtmlEncode(fUpload3.FileName) fUpload3.SaveAs(savePath3) End If End Sub Private Sub MyDataSource_Inserting(sender As Object, e As FormViewInsertEventArgs) Dim fu As FileUpload = DirectCast(frmDemande.FindControl("File1"), FileUpload) If fu.HasFile = True Then e.Values("fup1") = fu.FileName End If End Sub End Class <%@ Page Title="" Language="VB" MasterPageFile="~/Content/content.master" AutoEventWireup="false" CodeFile="default.aspx.vb" Inherits="Content_default" %> <asp:Content ID="HeaderContent" runat="server" ContentPlaceHolderID="HeadContent"> <style type="text/css"> .style1 { width: 100%; } .style2 { } .style5 { height: 26px; } .style6 { height: 46px; } </style> </asp:Content> <asp:Content ID="Content2" ContentPlaceHolderID="MainContent" Runat="Server"> <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConflictDetection="CompareAllValues" ConnectionString="<%$ ConnectionStrings:cn_NEW %>" DeleteCommand="DELETE FROM [tComptaDemEngag] WHERE [IDDemEngag] = @original_IDDemEngag AND (([ADlogin] = @original_ADlogin) OR ([ADlogin] IS NULL AND @original_ADlogin IS NULL)) AND (([objet] = @original_objet) OR ([objet] IS NULL AND @original_objet IS NULL)) AND (([langue_bdc] = @original_langue_bdc) OR ([langue_bdc] IS NULL AND @original_langue_bdc IS NULL)) AND (([delai_de_livraison] = @original_delai_de_livraison) OR ([delai_de_livraison] IS NULL AND @original_delai_de_livraison IS NULL)) AND (([fournisseur_nom] = @original_fournisseur_nom) OR ([fournisseur_nom] IS NULL AND @original_fournisseur_nom IS NULL)) AND (([fournisseur_rue] = @original_fournisseur_rue) OR ([fournisseur_rue] IS NULL AND @original_fournisseur_rue IS NULL)) AND (([fournisseur_cp] = @original_fournisseur_cp) OR ([fournisseur_cp] IS NULL AND @original_fournisseur_cp IS NULL)) AND (([fournisseur_localite] = @original_fournisseur_localite) OR ([fournisseur_localite] IS NULL AND @original_fournisseur_localite IS NULL)) AND (([fournisseur_pays] = @original_fournisseur_pays) OR ([fournisseur_pays] IS NULL AND @original_fournisseur_pays IS NULL)) AND (([personne_de_contact] = @original_personne_de_contact) OR ([personne_de_contact] IS NULL AND @original_personne_de_contact IS NULL)) AND (([montant_estime] = @original_montant_estime) OR ([montant_estime] IS NULL AND @original_montant_estime IS NULL)) AND (([projet_budget] = @original_projet_budget) OR ([projet_budget] IS NULL AND @original_projet_budget IS NULL)) AND (([adresse_livraison] = @original_adresse_livraison) OR ([adresse_livraison] IS NULL AND @original_adresse_livraison IS NULL)) AND (([adresse_autre] = @original_adresse_autre) OR ([adresse_autre] IS NULL AND @original_adresse_autre IS NULL)) AND (([remettre_bdc] = @original_remettre_bdc) OR ([remettre_bdc] IS NULL AND @original_remettre_bdc IS NULL)) AND (([remettre_autre] = @original_remettre_autre) OR ([remettre_autre] IS NULL AND @original_remettre_autre IS NULL)) AND (([Remarques] = @original_Remarques) OR ([Remarques] IS NULL AND @original_Remarques IS NULL))" InsertCommand="INSERT INTO [tComptaDemEngag] ([ADlogin], [objet], [langue_bdc], [delai_de_livraison], [fournisseur_nom], [fournisseur_rue], [fournisseur_cp], [fournisseur_localite], [fournisseur_pays], [personne_de_contact], [montant_estime], [projet_budget], [fup1], [adresse_livraison], [adresse_autre], [remettre_bdc], [remettre_autre], [Remarques]) VALUES (@ADlogin, @objet, @langue_bdc, @delai_de_livraison, @fournisseur_nom, @fournisseur_rue, @fournisseur_cp, @fournisseur_localite, @fournisseur_pays, @personne_de_contact, @montant_estime, @projet_budget, ,@fup1, @adresse_livraison, @adresse_autre, @remettre_bdc, @remettre_autre, @Remarques)" OldValuesParameterFormatString="original_{0}" SelectCommand="SELECT [ADlogin], [objet], [langue_bdc], [delai_de_livraison], [fournisseur_nom], [fournisseur_rue], [fournisseur_cp], [fournisseur_localite], [fournisseur_pays], [personne_de_contact], [montant_estime], [projet_budget], [adresse_livraison], [adresse_autre], [remettre_bdc], [remettre_autre], [Remarques], [IDDemEngag] FROM [tComptaDemEngag]" UpdateCommand="UPDATE [tComptaDemEngag] SET [ADlogin] = @ADlogin, [objet] = @objet, [langue_bdc] = @langue_bdc, [delai_de_livraison] = @delai_de_livraison, [fournisseur_nom] = @fournisseur_nom, [fournisseur_rue] = @fournisseur_rue, [fournisseur_cp] = @fournisseur_cp, [fournisseur_localite] = @fournisseur_localite, [fournisseur_pays] = @fournisseur_pays, [personne_de_contact] = @personne_de_contact, [montant_estime] = @montant_estime, [projet_budget] = @projet_budget, [adresse_livraison] = @adresse_livraison, [adresse_autre] = @adresse_autre, [remettre_bdc] = @remettre_bdc, [remettre_autre] = @remettre_autre, [Remarques] = @Remarques WHERE [IDDemEngag] = @original_IDDemEngag AND (([ADlogin] = @original_ADlogin) OR ([ADlogin] IS NULL AND @original_ADlogin IS NULL)) AND (([objet] = @original_objet) OR ([objet] IS NULL AND @original_objet IS NULL)) AND (([langue_bdc] = @original_langue_bdc) OR ([langue_bdc] IS NULL AND @original_langue_bdc IS NULL)) AND (([delai_de_livraison] = @original_delai_de_livraison) OR ([delai_de_livraison] IS NULL AND @original_delai_de_livraison IS NULL)) AND (([fournisseur_nom] = @original_fournisseur_nom) OR ([fournisseur_nom] IS NULL AND @original_fournisseur_nom IS NULL)) AND (([fournisseur_rue] = @original_fournisseur_rue) OR ([fournisseur_rue] IS NULL AND @original_fournisseur_rue IS NULL)) AND (([fournisseur_cp] = @original_fournisseur_cp) OR ([fournisseur_cp] IS NULL AND @original_fournisseur_cp IS NULL)) AND (([fournisseur_localite] = @original_fournisseur_localite) OR ([fournisseur_localite] IS NULL AND @original_fournisseur_localite IS NULL)) AND (([fournisseur_pays] = @original_fournisseur_pays) OR ([fournisseur_pays] IS NULL AND @original_fournisseur_pays IS NULL)) AND (([personne_de_contact] = @original_personne_de_contact) OR ([personne_de_contact] IS NULL AND @original_personne_de_contact IS NULL)) AND (([montant_estime] = @original_montant_estime) OR ([montant_estime] IS NULL AND @original_montant_estime IS NULL)) AND (([projet_budget] = @original_projet_budget) OR ([projet_budget] IS NULL AND @original_projet_budget IS NULL)) AND (([adresse_livraison] = @original_adresse_livraison) OR ([adresse_livraison] IS NULL AND @original_adresse_livraison IS NULL)) AND (([adresse_autre] = @original_adresse_autre) OR ([adresse_autre] IS NULL AND @original_adresse_autre IS NULL)) AND (([remettre_bdc] = @original_remettre_bdc) OR ([remettre_bdc] IS NULL AND @original_remettre_bdc IS NULL)) AND (([remettre_autre] = @original_remettre_autre) OR ([remettre_autre] IS NULL AND @original_remettre_autre IS NULL)) AND (([Remarques] = @original_Remarques) OR ([Remarques] IS NULL AND @original_Remarques IS NULL))"> <DeleteParameters> <asp:Parameter Name="original_IDDemEngag" Type="Int32" /> <asp:Parameter Name="original_ADlogin" Type="String" /> <asp:Parameter Name="original_objet" Type="String" /> <asp:Parameter Name="original_langue_bdc" Type="String" /> <asp:Parameter Name="original_delai_de_livraison" Type="String" /> <asp:Parameter Name="original_fournisseur_nom" Type="String" /> <asp:Parameter Name="original_fournisseur_rue" Type="String" /> <asp:Parameter Name="original_fournisseur_cp" Type="String" /> <asp:Parameter Name="original_fournisseur_localite" Type="String" /> <asp:Parameter Name="original_fournisseur_pays" Type="String" /> <asp:Parameter Name="original_personne_de_contact" Type="String" /> <asp:Parameter Name="original_montant_estime" Type="Int32" /> <asp:Parameter Name="original_projet_budget" Type="String" /> <asp:Parameter Name="original_adresse_livraison" Type="String" /> <asp:Parameter Name="original_adresse_autre" Type="String" /> <asp:Parameter Name="original_remettre_bdc" Type="String" /> <asp:Parameter Name="original_remettre_autre" Type="String" /> <asp:Parameter Name="original_Remarques" Type="String" /> </DeleteParameters> <InsertParameters> <asp:SessionParameter Name="ADLogin" SessionField="MyLogin" /> <asp:Parameter Name="objet" Type="String" /> <asp:Parameter Name="langue_bdc" Type="String" /> <asp:Parameter Name="delai_de_livraison" Type="String" /> <asp:Parameter Name="fournisseur_nom" Type="String" /> <asp:Parameter Name="fournisseur_rue" Type="String" /> <asp:Parameter Name="fournisseur_cp" Type="String" /> <asp:Parameter Name="fournisseur_localite" Type="String" /> <asp:Parameter Name="fournisseur_pays" Type="String" /> <asp:Parameter Name="personne_de_contact" Type="String" /> <asp:Parameter Name="montant_estime" Type="Int32" /> <asp:Parameter Name="projet_budget" Type="String" /> <asp:Parameter Name="fup1" Type="String" /> <asp:Parameter Name="adresse_livraison" Type="String" /> <asp:Parameter Name="adresse_autre" Type="String" /> <asp:Parameter Name="remettre_bdc" Type="String" /> <asp:Parameter Name="remettre_autre" Type="String" /> <asp:Parameter Name="Remarques" Type="String" /> </InsertParameters> <UpdateParameters> <asp:Parameter Name="ADlogin" Type="String" /> <asp:Parameter Name="objet" Type="String" /> <asp:Parameter Name="langue_bdc" Type="String" /> <asp:Parameter Name="delai_de_livraison" Type="String" /> <asp:Parameter Name="fournisseur_nom" Type="String" /> <asp:Parameter Name="fournisseur_rue" Type="String" /> <asp:Parameter Name="fournisseur_cp" Type="String" /> <asp:Parameter Name="fournisseur_localite" Type="String" /> <asp:Parameter Name="fournisseur_pays" Type="String" /> <asp:Parameter Name="personne_de_contact" Type="String" /> <asp:Parameter Name="montant_estime" Type="Int32" /> <asp:Parameter Name="projet_budget" Type="String" /> <asp:Parameter Name="adresse_livraison" Type="String" /> <asp:Parameter Name="adresse_autre" Type="String" /> <asp:Parameter Name="remettre_bdc" Type="String" /> <asp:Parameter Name="remettre_autre" Type="String" /> <asp:Parameter Name="Remarques" Type="String" /> <asp:Parameter Name="original_IDDemEngag" Type="Int32" /> <asp:Parameter Name="original_ADlogin" Type="String" /> <asp:Parameter Name="original_objet" Type="String" /> <asp:Parameter Name="original_langue_bdc" Type="String" /> <asp:Parameter Name="original_delai_de_livraison" Type="String" /> <asp:Parameter Name="original_fournisseur_nom" Type="String" /> <asp:Parameter Name="original_fournisseur_rue" Type="String" /> <asp:Parameter Name="original_fournisseur_cp" Type="String" /> <asp:Parameter Name="original_fournisseur_localite" Type="String" /> <asp:Parameter Name="original_fournisseur_pays" Type="String" /> <asp:Parameter Name="original_personne_de_contact" Type="String" /> <asp:Parameter Name="original_montant_estime" Type="Int32" /> <asp:Parameter Name="original_projet_budget" Type="String" /> <asp:Parameter Name="original_adresse_livraison" Type="String" /> <asp:Parameter Name="original_adresse_autre" Type="String" /> <asp:Parameter Name="original_remettre_bdc" Type="String" /> <asp:Parameter Name="original_remettre_autre" Type="String" /> <asp:Parameter Name="original_Remarques" Type="String" /> </UpdateParameters> </asp:SqlDataSource> <p><asp:FormView ID="frmDemande" runat="server" DataKeyNames="IDDemEngag" DataSourceID="SqlDataSource1" DefaultMode="Insert"> <EditItemTemplate> ADlogin: <asp:TextBox ID="ADloginTextBox" runat="server" Text='<%# Bind("ADlogin") %>' /> <br /> objet: <asp:TextBox ID="objetTextBox" runat="server" Text='<%# Bind("objet") %>' /> <br /> langue_bdc: <asp:TextBox ID="langue_bdcTextBox" runat="server" Text='<%# Bind("langue_bdc") %>' /> <br /> delai_de_livraison: <asp:TextBox ID="delai_de_livraisonTextBox" runat="server" Text='<%# Bind("delai_de_livraison") %>' /> <br /> fournisseur_nom: <asp:TextBox ID="fournisseur_nomTextBox" runat="server" Text='<%# Bind("fournisseur_nom") %>' /> <br /> fournisseur_rue: <asp:TextBox ID="fournisseur_rueTextBox" runat="server" Text='<%# Bind("fournisseur_rue") %>' /> <br /> fournisseur_cp: <asp:TextBox ID="fournisseur_cpTextBox" runat="server" Text='<%# Bind("fournisseur_cp") %>' /> <br /> fournisseur_localite: <asp:TextBox ID="fournisseur_localiteTextBox" runat="server" Text='<%# Bind("fournisseur_localite") %>' /> <br /> fournisseur_pays: <asp:TextBox ID="fournisseur_paysTextBox" runat="server" Text='<%# Bind("fournisseur_pays") %>' /> <br /> personne_de_contact: <asp:TextBox ID="personne_de_contactTextBox" runat="server" Text='<%# Bind("personne_de_contact") %>' /> <br /> montant_estime: <asp:TextBox ID="montant_estimeTextBox" runat="server" Text='<%# Bind("montant_estime") %>' /> <br /> projet_budget: <asp:TextBox ID="projet_budgetTextBox" runat="server" Text='<%# Bind("projet_budget") %>' /> <br /> adresse_livraison: <asp:TextBox ID="adresse_livraisonTextBox" runat="server" Text='<%# Bind("adresse_livraison") %>' /> <br /> adresse_autre: <asp:TextBox ID="adresse_autreTextBox" runat="server" Text='<%# Bind("adresse_autre") %>' /> <br /> remettre_bdc: <asp:TextBox ID="remettre_bdcTextBox" runat="server" Text='<%# Bind("remettre_bdc") %>' /> <br /> remettre_autre: <asp:TextBox ID="remettre_autreTextBox" runat="server" Text='<%# Bind("remettre_autre") %>' /> <br /> Remarques: <asp:TextBox ID="RemarquesTextBox" runat="server" Text='<%# Bind("Remarques") %>' /> <br /> IDDemEngag: <asp:Label ID="IDDemEngagLabel1" runat="server" Text='<%# Eval("IDDemEngag") %>' /> <br /> <asp:LinkButton ID="UpdateButton" runat="server" CausesValidation="True" CommandName="Update" Text="Update" /> <asp:LinkButton ID="UpdateCancelButton" runat="server" CausesValidation="False" CommandName="Cancel" Text="Cancel" /> </EditItemTemplate> <InsertItemTemplate> <table class="style1" width="80%" > <tr> <td class="style2" valign="top"> </td> <td class="attention" valign="top"> <strong>Joindre 3 offres/devis pour tout achat de matériel > 1.250 €</strong></td> </tr> <tr> <td class="style2" valign="top"> Objet:<br />(dans la langue du fournisseur!!)</td> <td valign="top"> <asp:TextBox ID="objetTextBox" runat="server" Columns="70" Rows="10" Text='<%# Bind("objet") %>' TextMode="MultiLine" /> <asp:RequiredFieldValidator ID="reqObjet" runat="server" ControlToValidate="objetTextBox" CssClass="attention" ErrorMessage="L'objet est obligatoire!">*</asp:RequiredFieldValidator> </td> </tr> <tr> <td class="style2" valign="top"> Langue du bon de commande:</td> <td valign="top"> <asp:DropDownList ID="dl_langue_bdc" runat="server" SelectedValue='<%# Bind("langue_bdc") %>'> <asp:ListItem Value="0" Selected="True">-- veuillez sélectionner --</asp:ListItem> <asp:ListItem Value="F">Français</asp:ListItem> <asp:ListItem Value="D">Deutsch</asp:ListItem> <asp:ListItem Value="UK">English</asp:ListItem> </asp:DropDownList> <asp:CompareValidator ID="CompareValidator1" runat="server" ControlToValidate="dl_langue_bdc" CssClass="attention" ErrorMessage="La langue du bon de commande est obligatoire!" Operator="NotEqual" ValueToCompare="0">*</asp:CompareValidator> </td> </tr> <tr> <td class="style2" valign="top"> Délai delivraison:</td> <td valign="top"> <asp:TextBox ID="delai_de_livraisonTextBox" runat="server" Text='<%# Bind("delai_de_livraison") %>' /> <asp:RequiredFieldValidator ID="reqDelai" runat="server" ControlToValidate="delai_de_livraisonTextBox" CssClass="attention" ErrorMessage="Le délai de livraison est obligatoire!">*</asp:RequiredFieldValidator> </td> </tr> <tr> <td class="style2" valign="top"> Fournisseur (nom):</td> <td valign="top"> <asp:TextBox ID="fournisseur_nomTextBox" runat="server" Columns="50" Text='<%# Bind("fournisseur_nom") %>'></asp:TextBox> <asp:RequiredFieldValidator ID="reqFournisseur" runat="server" ControlToValidate="fournisseur_nomTextBox" CssClass="attention" ErrorMessage="Le nom du fournisseur est obligatoire!">*</asp:RequiredFieldValidator> </td> </tr> <tr> <td class="style2" valign="top"> Fournisseur (rue):</td> <td valign="top"> <asp:TextBox ID="fournisseur_rueTextBox" runat="server" Columns="30" Text='<%# Bind("fournisseur_rue") %>'></asp:TextBox> <asp:RequiredFieldValidator ID="reqFournisseur0" runat="server" ControlToValidate="fournisseur_rueTextBox" CssClass="attention" ErrorMessage="La rue du fournisseur est obligatoire!">*</asp:RequiredFieldValidator> </td> </tr> <tr> <td class="style2" valign="top"> Fournisseur (cp & localité):</td> <td valign="top"> <asp:TextBox ID="fournisseur_cpTextBox" runat="server" Columns="8" Text='<%# Bind("fournisseur_cp") %>'></asp:TextBox> <asp:RequiredFieldValidator ID="reqFournisseur3" runat="server" ControlToValidate="fournisseur_cpTextBox" CssClass="attention" ErrorMessage="Le code postal du fournisseur est obligatoire!">*</asp:RequiredFieldValidator> <asp:TextBox ID="fournisseur_localiteTextBox" runat="server" Columns="30" Text='<%# Bind("fournisseur_localite") %>'></asp:TextBox> <asp:RequiredFieldValidator ID="reqFournisseur1" runat="server" ControlToValidate="fournisseur_localiteTextBox" CssClass="attention" ErrorMessage="La localité du fournisseur est obligatoire!">*</asp:RequiredFieldValidator> </td> </tr> <tr> <td class="style2" valign="top"> Fournisseur (pays):</td> <td valign="top"> <asp:TextBox ID="fournisseur_paysTextBox" runat="server" Columns="30" Text='<%# Bind("fournisseur_pays") %>' /> <asp:RequiredFieldValidator ID="reqFournisseur2" runat="server" ControlToValidate="fournisseur_paysTextBox" CssClass="attention" ErrorMessage="Le pays du fournisseur est obligatoire!">*</asp:RequiredFieldValidator> </td> </tr> <tr> <td class="style2" valign="top"> Fournisseur (personne de contact):</td> <td valign="top"> <asp:TextBox ID="personne_de_contactTextBox" runat="server" Columns="50" Text='<%# Bind("personne_de_contact") %>' /> <asp:RequiredFieldValidator ID="reqContact" runat="server" ControlToValidate="personne_de_contactTextBox" CssClass="attention" ErrorMessage="La personne contact est obligatoire!">*</asp:RequiredFieldValidator> </td> </tr> <tr> <td class="style2" valign="top"> Montant maximal estimé (en €, TTC):</td> <td valign="top"> <asp:TextBox ID="montant_estimeTextBox" runat="server" Columns="15" Text='<%# Bind("montant_estime") %>' /> <asp:RequiredFieldValidator ID="eqMontant" runat="server" ControlToValidate="montant_estimeTextBox" CssClass="attention" ErrorMessage="Le montant estimé est obligatoire!">*</asp:RequiredFieldValidator> <asp:RegularExpressionValidator ID="reqMontantNombre" runat="server" ControlToValidate="montant_estimeTextBox" ErrorMessage="Montant estimé: Il faut saisir un nombre!" ValidationExpression="^\d+$" CssClass="attention">Il faut saisir un nombre!</asp:RegularExpressionValidator> </td> </tr> <tr> <td class="style2" valign="top"> Projet/budget:</td> <td valign="top"> <asp:TextBox ID="projet_budgetTextBox" runat="server" Columns="70" Text='<%# Bind("projet_budget") %>' /> <asp:RequiredFieldValidator ID="reqProjet" runat="server" ControlToValidate="projet_budgetTextBox" CssClass="attention" ErrorMessage="Le projet/budget est obligatoire!">*</asp:RequiredFieldValidator> </td> </tr> <tr> <td class="style5" valign="top"> Offre 1:</td> <td class="style5" valign="top"> <asp:FileUpload ID="file1" runat="server" /> </td> </tr> <tr> <td class="style2" valign="top"> Offre 2:</td> <td valign="top"> <asp:FileUpload ID="file2" runat="server" /> </td> </tr> <tr> <td class="style2" valign="top"> Offre 3:</td> <td valign="top"> <asp:FileUpload ID="file3" runat="server" /> </td> </tr> <tr> <td class="style2" valign="top"> Adresse de livraison:</td> <td valign="top"> <asp:DropDownList ID="dlLivraison" runat="server" SelectedValue='<%# Bind("adresse_livraison") %>'> <asp:ListItem Value="0">-- veuillez sélectionner --</asp:ListItem> <asp:ListItem>Rue Plaetis</asp:ListItem> <asp:ListItem>Rue Münster</asp:ListItem> <asp:ListItem>autre</asp:ListItem> </asp:DropDownList> <asp:CompareValidator ID="CompareValidator2" runat="server" ControlToValidate="dlLivraison" CssClass="attention" ErrorMessage="L'adresse de livraison est obligatoire!" Operator="NotEqual" ValueToCompare="0">*</asp:CompareValidator> </td> </tr> <tr> <td class="style2" valign="top"> Adresse (si autre):</td> <td valign="top"> <asp:TextBox ID="fournisseur_adresse_autreTextBox" runat="server" Columns="30" Rows="3" TextMode="MultiLine" Text='<%# Bind("adresse_autre") %>'></asp:TextBox> </td> </tr> <tr> <td class="style2" valign="top"> Bon de commande:</td> <td valign="top"> <asp:DropDownList ID="dl_bdc_envoyer" runat="server" SelectedValue='<%# Bind("remettre_bdc") %>'> <asp:ListItem Value="0">-- veuillez sélectionner ---</asp:ListItem> <asp:ListItem>à remettre au demandeur</asp:ListItem> <asp:ListItem>à remettre au une autre personne</asp:ListItem> <asp:ListItem>à envoyer au fournisseur</asp:ListItem> </asp:DropDownList> <asp:CompareValidator ID="CompareValidator3" runat="server" ControlToValidate="dl_bdc_envoyer" CssClass="attention" ErrorMessage="Il faut indiquer à qui remettre ou envoyer le bon de commande!" Operator="NotEqual" ValueToCompare="0">*</asp:CompareValidator> </td> </tr> <tr> <td class="style2" valign="top"> Remettre à une autre personne:</td> <td valign="top"> <asp:TextBox ID="TextBox1" runat="server" Text='<%# bind("remettre_autre") %>'></asp:TextBox> </td> </tr> <tr> <td class="style2" valign="top"> Remarques:</td> <td valign="top"> <asp:TextBox ID="remarquesTextBox" runat="server" Columns="50" Rows="3" Text='<%# Bind("remarques") %>' TextMode="MultiLine"></asp:TextBox> </td> </tr> <tr> <td class="style2" valign="top" align="right"> <asp:Button ID="Button1" runat="server" CommandName="Insert" Text="sauvegarder" onclick="Button1_Click" /> </td> <td valign="top"> <asp:Button ID="Button2" runat="server" CausesValidation="False" CommandName="Cancel" Text="annuler" /> </td> </tr> <tr> <td class="style2" colspan="2" valign="top"> <asp:ValidationSummary ID="ValidationSummary1" runat="server" CssClass="attention" /> </td> </tr> </table> <br /> </InsertItemTemplate> <ItemTemplate> ADlogin: <asp:Label ID="ADloginLabel" runat="server" Text='<%# Bind("ADlogin") %>' /> <br /> objet: <asp:Label ID="objetLabel" runat="server" Text='<%# Bind("objet") %>' /> <br /> langue_bdc: <asp:Label ID="langue_bdcLabel" runat="server" Text='<%# Bind("langue_bdc") %>' /> <br /> delai_de_livraison: <asp:Label ID="delai_de_livraisonLabel" runat="server" Text='<%# Bind("delai_de_livraison") %>' /> <br /> fournisseur_nom: <asp:Label ID="fournisseur_nomLabel" runat="server" Text='<%# Bind("fournisseur_nom") %>' /> <br /> fournisseur_rue: <asp:Label ID="fournisseur_rueLabel" runat="server" Text='<%# Bind("fournisseur_rue") %>' /> <br /> fournisseur_cp: <asp:Label ID="fournisseur_cpLabel" runat="server" Text='<%# Bind("fournisseur_cp") %>' /> <br /> fournisseur_localite: <asp:Label ID="fournisseur_localiteLabel" runat="server" Text='<%# Bind("fournisseur_localite") %>' /> <br /> fournisseur_pays: <asp:Label ID="fournisseur_paysLabel" runat="server" Text='<%# Bind("fournisseur_pays") %>' /> <br /> personne_de_contact: <asp:Label ID="personne_de_contactLabel" runat="server" Text='<%# Bind("personne_de_contact") %>' /> <br /> montant_estime: <asp:Label ID="montant_estimeLabel" runat="server" Text='<%# Bind("montant_estime") %>' /> <br /> projet_budget: <asp:Label ID="projet_budgetLabel" runat="server" Text='<%# Bind("projet_budget") %>' /> <br /> adresse_livraison: <asp:Label ID="adresse_livraisonLabel" runat="server" Text='<%# Bind("adresse_livraison") %>' /> <br /> adresse_autre: <asp:Label ID="adresse_autreLabel" runat="server" Text='<%# Bind("adresse_autre") %>' /> <br /> remettre_bdc: <asp:Label ID="remettre_bdcLabel" runat="server" Text='<%# Bind("remettre_bdc") %>' /> <br /> remettre_autre: <asp:Label ID="remettre_autreLabel" runat="server" Text='<%# Bind("remettre_autre") %>' /> <br /> Remarques: <asp:Label ID="RemarquesLabel" runat="server" Text='<%# Bind("Remarques") %>' /> <br /> IDDemEngag: <asp:Label ID="IDDemEngagLabel" runat="server" Text='<%# Eval("IDDemEngag") %>' /> <br /> <asp:LinkButton ID="EditButton" runat="server" CausesValidation="False" CommandName="Edit" Text="Edit" /> <asp:LinkButton ID="DeleteButton" runat="server" CausesValidation="False" CommandName="Delete" Text="Delete" /> <asp:LinkButton ID="NewButton" runat="server" CausesValidation="False" CommandName="New" Text="New" /> </ItemTemplate> </asp:FormView> </p> </asp:Content>basheerkal
Star
10672 Points
2426 Posts
Re: How to save the filename from an FileUpload control on a FormView?
Mar 21, 2012 03:27 PM|LINK
Hope this is the FileUpload control from which you want to save the file name.
And from insert command it is seen that you want to insert it in the field "fup1" OK?
Then ItemInserting event should be like this.
And the insert paramaeter for your datasource is
Now tell me if you get any error. No code in any of the events of your SQLDdatasource please.
(Please note there is an extra coma juste before "@fup1" in your InsertCommand)
(Talk less..Work more)
Subliminal V...
Member
604 Points
195 Posts
Re: How to save the filename from an FileUpload control on a FormView?
Mar 21, 2012 03:35 PM|LINK
Hi basheer,
Thanks for answering! I've got everything like you said I should and I've also deleted that silly comma there!?
But now when I click on 'save' I'm redirected to the confirmation page (without an error message) although the data has not been saved in the database ... It's like I said before, when I add fup1 to the InsertCommand then the data is not saved anymore ...
basheerkal
Star
10672 Points
2426 Posts
Re: How to save the filename from an FileUpload control on a FormView?
Mar 21, 2012 03:50 PM|LINK
I was assuming You perfom insert by clicking insert button..!!!
No insert Button in your formView?
Put an insert Link in item template and put all the code to save the files in server in ItemInserting event along with the existing code.
Now I hope only Uploading might have done without inserting..check it?
B
(Talk less..Work more)
basheerkal
Star
10672 Points
2426 Posts
Re: How to save the filename from an FileUpload control on a FormView?
Mar 21, 2012 05:24 PM|LINK
Dear Void
Plese check this simple example code. My fields are 'ID' and 'Filename'
HTML for FormView and SQL DataSource
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:ApplicationServices %>" InsertCommand="INSERT INTO filetable (filename) VALUES (@FileName)" SelectCommand="SELECT filetable.* FROM filetable"> <InsertParameters> <asp:Parameter Name="FileName" /> </InsertParameters> </asp:SqlDataSource> <asp:FormView ID="FormView1" runat="server" DataSourceID="SqlDataSource1" oniteminserting="FormView1_ItemInserting" AllowPaging="True" BorderColor="#009900" BorderStyle="Solid"> <InsertItemTemplate> Select File: <asp:FileUpload ID="FileUpload1" runat="server" /> <br /> <asp:LinkButton ID="InsertButton" runat="server" CausesValidation="True" CommandName="Insert" Text="Insert" /> <asp:LinkButton ID="InsertCancelButton" runat="server" CausesValidation="False" CommandName="Cancel" Text="Cancel" /> </InsertItemTemplate> <ItemTemplate> Id: <asp:Label ID="IdLabel" runat="server" Text='<%# Eval("Id") %>' /> <br /> File: <asp:Label ID="filenameLabel" runat="server" Text='<%# Bind("FileName") %>'/> <br /> <asp:LinkButton ID="NewButton" runat="server" CausesValidation="False" CommandName="New" Text="New" /> </ItemTemplate> </asp:FormView>Code in ItemInserting ebevent of my FormView.
Buy clicking insert button It saves the file in my application folder and file name is inserted in database
protected void FormView1_ItemInserting(object sender, FormViewInsertEventArgs e) { FileUpload fu = (FileUpload)(FormView1.FindControl("FileUpload1")); if(fu.HasFile==true) { e.Values["filename"] =fu.FileName; fu.SaveAs(Server.MapPath("~/"+fu.FileName)); Response.Write(fu.FileName +" Uploaded"); } }Hope this will give you an idea..what I was telling.
B
(Talk less..Work more)
Subliminal V...
Member
604 Points
195 Posts
Re: How to save the filename from an FileUpload control on a FormView?
Mar 22, 2012 07:05 AM|LINK
I do! By clicking the insert button on the FormView!
Subliminal V...
Member
604 Points
195 Posts
Re: How to save the filename from an FileUpload control on a FormView?
Mar 22, 2012 09:00 AM|LINK
Ok, that works. Now I have to find out why it doesn't work on my page ...
Subliminal V...
Member
604 Points
195 Posts
Re: How to save the filename from an FileUpload control on a FormView?
Mar 22, 2012 09:19 AM|LINK
Ok, it works now! The name gets finally saved into the DB. I had a lot of small errors in my code ... d'oh (mainly wrong references)
Subliminal V...
Member
604 Points
195 Posts
Re: How to save the filename from an FileUpload control on a FormView?
Mar 22, 2012 09:39 AM|LINK
I also had both an ButtonClick and an ItemInserting event, that seemed to cause some problems too ... I've put everything in thie ItemInserting event now.