Bonjour,

Voici mes codes HTML /ASP et +csharp:

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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
<form id="form1" runat="server" enctype="multipart/form-data">
        <asp:ScriptManager ID="ScriptManager1" runat="server">
        </asp:ScriptManager>
        <div id="dvGrid" style="padding: 10px; width: 550px">
            <asp:UpdatePanel ID="UpdatePanel1" runat="server">
                <ContentTemplate>
                    <asp:GridView ID="GridView1" runat="server" Width="550px"
                        AutoGenerateColumns="false" Font-Names="Arial"
                        Font-Size="11pt" AlternatingRowStyle-BackColor="#C2D69B"
                        HeaderStyle-BackColor="green" AllowPaging="true" ShowFooter="true"
                        OnPageIndexChanging="OnPaging" OnRowEditing="EditCustomer"
                        OnRowUpdating="UpdateCustomer" OnRowCancelingEdit="CancelEdit"
                        PageSize="10">
                        <Columns>
                            <asp:TemplateField ItemStyle-Width="30px" HeaderText="CustomerID">
                                <ItemTemplate>
                                    <asp:Label ID="lblID" runat="server" Text='<%# Eval("ID")%>'></asp:Label>
                                </ItemTemplate>
                                <FooterTemplate>
                                    <!--<asp:TextBox ID="txtID" Width="40px" MaxLength="5" runat="server"></asp:TextBox>-->
                                </FooterTemplate>
                            </asp:TemplateField>
                            <asp:TemplateField ItemStyle-Width="100px" HeaderText="Name">
                                <ItemTemplate>
                                    <asp:Label ID="lblName" runat="server" Text='<%# Eval("Name")%>'></asp:Label>
                                </ItemTemplate>
                                <EditItemTemplate>
                                    <asp:TextBox ID="txtName" runat="server" Text='<%# Eval("Name")%>'></asp:TextBox>
                                </EditItemTemplate>
                                <FooterTemplate>
                                    <asp:TextBox ID="txtName" runat="server"></asp:TextBox>
                                </FooterTemplate>
                            </asp:TemplateField>
                            <asp:TemplateField ItemStyle-Width="150px" HeaderText="Logo">
                                <ItemTemplate>
                                    <asp:Label ID="lblLogo" runat="server" Text='<%# Eval("Logo")%>'></asp:Label>
                                </ItemTemplate>
                                <EditItemTemplate>
                                    <input id="docLogo" type="file" runat="Server" />
                                </EditItemTemplate>
                                <FooterTemplate>
                                    <input id="docLogo" type="file" runat="Server" />
                                </FooterTemplate>
                            </asp:TemplateField>
                            <asp:TemplateField ItemStyle-Width="150px" HeaderText="Site internet">
                                <ItemTemplate>
                                    <asp:Label ID="lblURL" runat="server" Text='<%# Eval("URL")%>'></asp:Label>
                                </ItemTemplate>
                                <EditItemTemplate>
                                    <asp:TextBox ID="txtURL" runat="server" Text='<%# Eval("URL")%>'></asp:TextBox>
                                </EditItemTemplate>
                                <FooterTemplate>
                                    <asp:TextBox ID="txtURL" runat="server"></asp:TextBox>
                                </FooterTemplate>
                            </asp:TemplateField>
                            <asp:TemplateField>
                                <ItemTemplate>
                                    <asp:LinkButton ID="lnkRemove" runat="server" CommandArgument='<%# Eval("ID")%>'
                                        OnClientClick="return confirm('confirmer la suppression?')"
                                        Text="Delete" OnClick="DeleteCustomer"></asp:LinkButton>
                                </ItemTemplate>
                                <FooterTemplate>
                                    <asp:Button ID="btnAdd" runat="server" Text="Ajouter" OnClick="AddNewCustomer" />
                                </FooterTemplate>
                            </asp:TemplateField>
                            <asp:CommandField ShowEditButton="True" />
                        </Columns>
                        <AlternatingRowStyle BackColor="#C2D69B" />
                    </asp:GridView>
                </ContentTemplate>
                <Triggers>
                    <asp:AsyncPostBackTrigger ControlID="GridView1" />
                </Triggers>
            </asp:UpdatePanel>
        </div>
    </form>
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
protected void UpdateCustomer(object sender, GridViewUpdateEventArgs e)
    {
        string uploadedFile = uploadedFile();
 
        string _id = ((Label)GridView1.Rows[e.RowIndex].FindControl("lblID")).Text;
        string _Name = ((TextBox)GridView1.Rows[e.RowIndex].FindControl("txtName")).Text;
        string _Logo = uploadedfile;
        string _URL = ((TextBox)GridView1.Rows[e.RowIndex].FindControl("txtURL")).Text;
        SqlConnection con = new SqlConnection(connectionString);
        SqlCommand cmd = new SqlCommand();
        cmd.CommandType = CommandType.Text;
        cmd.CommandText = "update dbo.Sponsors set Name=@Name,Logo=@Logo,URL=@URL " +
         "where ID=@ID;" +
         "select ID,Name,Logo,URL from dbo.Sponsors";
        cmd.Parameters.Add("@ID", SqlDbType.VarChar).Value = _id;
        cmd.Parameters.Add("@Name", SqlDbType.VarChar).Value = _Name;
        cmd.Parameters.Add("@Logo", SqlDbType.VarChar).Value = _Logo;
        cmd.Parameters.Add("@URL", SqlDbType.VarChar).Value = _URL;
        GridView1.EditIndex = -1;
        GridView1.DataSource = GetData(cmd);
        GridView1.DataBind();
    }
 
    protected string UploadFile()
    {
        string filepath = "C:\\Uploads";
        string uploadedfile = "";
 
        if (docLogo.PostedFile != null)
        {
            try
            {
                docLogo.PostedFile.SaveAs(filepath + "\\" + docLogo.PostedFile.FileName);
                Span1.InnerHtml = "Téléchargement effectué avec succès.";
                uploadedfile = filepath + "\\" + docLogo.PostedFile.FileName;
                return uploadedfile;
            }
            catch (Exception ex)
            {
                Span1.InnerHtml = "Error saving file <b>C:\\" + docLogo.Value + "</b><br>" + ex.ToString();
            }
 
        }
 
        return uploadedfile;
    }
Lorsque j'essaie d'uploadé une image, il passe à null à la ligne: if (docLogo.PostedFile != null) dans ma fonction upload. Ici utilisé dans la fonction d'update, c'est le même effet dans la fonction d'ajout.

Le débug ne m'a rien donné de congruent et mes codes sont du quasi copier coller de la page suivante: https://msdn.microsoft.com/en-us/library/aa478971.aspx aussi si vous pouviez m'aider à résoudre ce problème, ce serait super

Bien à vous