Bonjour,

Suite des mes nombreuses questions sur le developement web .net.

Sur ma page, une formview affiche le contenu d'une table (la ligne la plus récente).

Voici le code :

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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
<%@ Page Language="C#" MasterPageFile="~/MasterPage_admin.master" Title="Untitled Page" %>
 
<script runat="server">
 
    protected void FormView1_PageIndexChanging(object sender, FormViewPageEventArgs e)
    {
 
    }
 
    protected void FormView1_PageIndexChanging1(object sender, FormViewPageEventArgs e)
    {
 
    }
</script>
 
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
   <div style="text-align:left">
    <asp:FormView ID="FormView1" runat="server" DataKeyNames="idinfo" DataSourceID="SqlDataSource1"
        Height="163px" OnPageIndexChanging="FormView1_PageIndexChanging1" Width="600px" AllowPaging="True">
        <EditItemTemplate>
            idinfo:
            <asp:Label ID="idinfoLabel1" runat="server" Text='<%# Eval("idinfo") %>'></asp:Label><br /> 
            date:
            <asp:TextBox ID="dateTextBox" runat="server" Text='<%# Bind("date") %>'>
            </asp:TextBox><br />
            titre:
            <asp:TextBox ID="titreTextBox" runat="server" Text='<%# Bind("titre") %>'>
            </asp:TextBox><br />
            Texte :
            <asp:TextBox ID="infoTextBox" runat="server" Text='<%# Bind("info") %>' Height="153px" Width="563px" TextMode="MultiLine" MaxLength="250">
            </asp:TextBox><br />
            <asp:LinkButton ID="UpdateButton" runat="server" CausesValidation="True" CommandName="Update"
                Text="Mettre à jour">
            </asp:LinkButton>
            <asp:LinkButton ID="UpdateCancelButton" runat="server" CausesValidation="False" CommandName="Cancel"
                Text="Annuler">
            </asp:LinkButton>
        </EditItemTemplate>
        <InsertItemTemplate>
            date:
            <asp:TextBox ID="dateTextBox" runat="server" Text='<%# Bind("date") %>'>
            </asp:TextBox><br />
            Titre:
            <asp:TextBox ID="titreTextBox" runat="server" Text='<%# Bind("titre") %>' Height="18px" Width="519px"></asp:TextBox><br />
            <br />
            Votre texte :<br />
            <asp:TextBox ID="infoTextBox" runat="server" Text='<%# Bind("info") %>' Height="153px" Width="563px" TextMode="MultiLine" MaxLength="250"></asp:TextBox><br />
            <asp:LinkButton ID="InsertButton" runat="server" CausesValidation="True" CommandName="Insert"
                Text="Insérer">
            </asp:LinkButton>
            <asp:LinkButton ID="InsertCancelButton" runat="server" CausesValidation="False" CommandName="Cancel"
                Text="Annuler">
            </asp:LinkButton>
        </InsertItemTemplate>
        <ItemTemplate>
            Edito numéro :
            <asp:Label ID="idinfoLabel" runat="server" Text='<%# Eval("idinfo") %>'></asp:Label> Publié
            le:
            <asp:Label ID="dateLabel" runat="server" Text='<%# Bind("date") %>'></asp:Label><br /><br />
            Titre:
            <asp:Label ID="titreLabel" runat="server" Text='<%# Bind("titre") %>'></asp:Label><br /><br />
            Texte:
            <asp:Label ID="infoLabel" runat="server" Text='<%# Bind("info") %>'></asp:Label><br /><br />
            <div class="bouton_modif">
            <asp:LinkButton ID="EditButton" runat="server" CausesValidation="False" CommandName="Edit"
                Text="Modifier"></asp:LinkButton>
            <asp:LinkButton ID="DeleteButton" runat="server" CausesValidation="False" CommandName="Delete"
                Text="Supprimer"></asp:LinkButton>
            <asp:LinkButton ID="NewButton" runat="server" CausesValidation="False" CommandName="New"
                Text="Nouveau"></asp:LinkButton></div>
        </ItemTemplate>
    </asp:FormView>
    <br />
    <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:intranetConnectionString %>"
        DeleteCommand="DELETE FROM [infoaccueil] WHERE [idinfo] = @idinfo" InsertCommand="INSERT INTO [infoaccueil] ([date], [titre], [info]) VALUES (@date, @titre, @info)"
        SelectCommand="SELECT * FROM [infoaccueil] ORDER BY [idinfo] DESC" UpdateCommand="UPDATE [infoaccueil] SET [date] = @date, [titre] = @titre, [info] = @info WHERE [idinfo] = @idinfo">
        <DeleteParameters>
            <asp:Parameter Name="idinfo" Type="Int32" />
        </DeleteParameters>
        <UpdateParameters>
            <asp:Parameter Name="date" Type="String" />
            <asp:Parameter Name="titre" Type="String" />
            <asp:Parameter Name="info" Type="String" />
            <asp:Parameter Name="idinfo" Type="Int32" />
        </UpdateParameters>
        <InsertParameters>
            <asp:Parameter Name="idinfo" Type="Int32" />
            <asp:Parameter Name="date" Type="String" />
            <asp:Parameter Name="titre" Type="String" />
            <asp:Parameter Name="info" Type="String" />
        </InsertParameters>
    </asp:SqlDataSource>
    </div>
</asp:Content>

J'aimerais codé le test suivant:

Je compte le nombre de résultat du Select *.... si la valeur est 0 (rien dans la table), j'affiche un message, sinon, j'affiche la FormView comme c'est le cas actuellement.

Je ne sais pas du tout comment m'y prendre (sauf pour le code SQL à faire). Merci pour votre aide.