Bonjour,
Voila, j'ai mis un formView dans ma page afin d'afficher quelques informations provenant d'une table, j'ai lié mon formView à un objet sqlDataSource.
Le mode visualisation fonctionne parfaitement, par contre en mode modification ca ne marche pas.
J'aimerais savoir si quelqu'un peut me donner une piste car je suis vraiment bloqué.
Voila le code que j'ai écrit :
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
|
<asp:formview id="ObservationFormView"
datasourceid="SqlObservationsSource"
allowpaging="true"
datakeynames="ID_OBSERVATION"
headertext="Liste des observations"
emptydatatext="Aucune observation trouvée."
OnItemUpdating="ObservationFormView_ItemUpdating"
OnModeChanging="ObservationFormView_ModeChanging"
runat="server" >
<headerstyle backcolor="CornFlowerBlue"
forecolor="White"
font-size="14"
horizontalalign="Center"
wrap="false"/>
<rowstyle backcolor="LightBlue"
wrap="false"/>
<pagerstyle backcolor="CornFlowerBlue"/>
<itemtemplate>
<table>
<tr valign="bottom" >
<td width="1"></td>
<td class="formLibelle">Date : </td>
<td class="formvaleur"><%# Eval("DATEOBS") %></td>
</tr>
<tr valign="bottom" >
<td width="1"></td>
<td class="formLibelle">Origine : </td>
</tr>
<tr valign="bottom" >
<td width="1"></td>
<td class="formLibelle" colspan="2">Observation : </td>
</tr>
<tr>
<td></td>
<td colspan="2" class="formValeur"><%# Eval("OBSERVATION")%></td>
</tr>
<tr>
<td colspan="3">
<asp:linkbutton id="Edit" commandname="Edit" runat="server"/>
</td>
</tr>
</table>
</itemtemplate>
<edititemtemplate>
<table>
<tr valign="bottom" >
<td width="1"></td>
<td class="formLibelle">Date : </td>
<td class="formValeur"><%# Eval("DATEOBS") %></td>
</tr>
<tr valign="bottom" >
<td width="1"></td>
<td class="formLibelle">Origine : </td>
<td class="formValeur"><%# Eval("ORIGINE") %></td>
</tr>
<tr valign="bottom" >
<td width="1"></td>
<td class="formLibelle" colspan="2">Observation : </td>
</tr>
<tr>
<td></td>
<td colspan="2"><asp:TextBox runat="server" ID="txtObservationsEdit" TextMode="MultiLine" Width="500" Rows="7" Text='<%# Bind("OBSERVATION")%>' /></td>
</tr>
<tr>
<td colspan="2">
<asp:linkbutton id="UpdateButton" text="Mettre à jour" commandname="Update" runat="server"/>
<asp:linkbutton id="CancelButton" text="Annuler" commandname="Cancel" runat="server"/>
</td>
</tr>
</table>
</edititemtemplate>
<pagersettings position="Bottom" mode="Numeric"/>
</asp:formview>
<br /><br />
<asp:Label ID="lblMessageFormView" runat="server" EnableViewState="false" CssClass="controleSaisie"></asp:Label>
<asp:SqlDataSource ID="SqlObservationsSource" runat="server">
</asp:SqlDataSource> |
Aui final, il n'y a que le champ observation que je veux modifier.
L'objet sqldatasource est intialisé dans le page_Load car la chaine de connexion est inscrite dans un fichier de config. C'est aussi dans le page_Load que je définis la commande select et la commande update pour le sqldateSource. Et malgré tout la modification ne marche pas, la nouvelle valeur n'est jamais prise en compte.
Edit : Voila a quoi ressemble ma commande update :
SqlObservationsSource.UpdateCommand = "UPDATE OBSERVATION SET [OBSERVATION] = @OBSERVATION WHERE [ID_OBSERVATION] = @ID_OBSERVATION";
Partager