Update ne marche plus après avoir ajouté un Insert dans un Gridview
Bonjour à tous,
J'utilise un gridview pour gérer une BDD Access pour l'instant.
Les Update et Delete fonctionnaient bien.
J'ai ajouté un Insert sur la ligne du Footer et depuis l'UPdate ne marche plus.
(par contre Insert fonctionne bien).
Voici des bouts de code :
Code:
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
|
<asp:CommandField ShowEditButton="True" />
<asp:TemplateField HeaderText="No ID" SortExpression="id">
<ItemTemplate>
<asp:Label ID="diplomeID" runat="server" Text='<%# Bind("id") %>'></asp:Label>
</ItemTemplate>
<FooterTemplate>
<asp:Button ID="AjoutDip" Text="Ajouter" ValidationGroup="Ajout"
runat="server" onclick="InsertDip" />
</FooterTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Libellé" SortExpression="libelle">
<ItemTemplate>
<asp:Label ID="Libel" runat="server" Text='<%# Bind("libelle") %>'></asp:Label>
</ItemTemplate>
<FooterTemplate>
<asp:TextBox ID="NewLibelle" ValidationGroup="Ajout" runat="server"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidatorNewLib" ValidationGroup="Ajout"
runat="server" ControlToValidate="NewLibelle" Display="Dynamic"
ForeColor="Red" ErrorMessage="Le libellé est obligatoire.">
* </asp:RequiredFieldValidator>
</FooterTemplate>
<FooterStyle Wrap="false" />
</asp:TemplateField>
...
<asp:SqlDataSource ID="SqlDataSourceDip" Runat="server"
SelectCommand="SELECT [id], [libelle], [libellelong] FROM [diplome]"
InsertCommand="INSERT into diplome (libelle, libellelong) values (@NewLibelle, @NewLibellelong)"
UpdateCommand="UPDATE [diplome] SET [libelle] = @libelle, [libellelong] = @libellelong WHERE [id] = @id"
...
<InsertParameters>
<asp:Parameter Name="NewLibelle"/>
<asp:Parameter Name="NewLibellelong"/>
</InsertParameters>
<DeleteParameters>
<asp:Parameter Name="diplomeID" />
</DeleteParameters>
<UpdateParameters>
<asp:Parameter Name="libelle"/>
<asp:Parameter Name="id" />
</UpdateParameters>
</asp:SqlDataSource>
... |
et dans le .cs :
Code:
1 2 3 4 5 6 7 8 9 10
|
protected void InsertDip(object sender, EventArgs e)
{
TextBox newlibtxt = (TextBox)GVDiplomes.FooterRow.FindControl("NewLibelle");
SqlDataSourceDip.InsertParameters["NewLibelle"].DefaultValue = newlibtxt.Text;
TextBox newliblongtxt = (TextBox)GVDiplomes.FooterRow.FindControl("NewLibellelong");
SqlDataSourceDip.InsertParameters["NewLibellelong"].DefaultValue = newliblongtxt.Text;
SqlDataSourceDip.Insert();
} |
D'où peut bien venir le problème ?
J'espère avoir été clair dans mes explications.
Merci pour vos réponses.