none
probleme saisie dans un formulaire RRS feed

  • Question

  • bonjour,
    je realise une application web sous visual studio en asp.net vb.
    lors de la saisie d'un formulaire j'ai un message d'erreur me montrant mon code ce message m'indique :
    [IMG]H:\Sauvegardes\messerreurappli.JPG[/IMG]

    l'exception format exception n'a pas été gérée par le code utilisateur.
    la chaine doit avoir une longeur d'un et un seul caractere

    conseil de depannage :
    assurez vous que le format des arguments de votre methode est correct.
    lors de la convertion d'une chaine en objet datetime, analyser la chaine pour prendre la date avant de la placer chaque variable dans l'objet datetime.

    je pense que le probleme vient du format date mais j'ai regarder dans mon code et dans ma base c'est le meme format "datetime"

    pour selection la date  dans mon formmulaire, j'utilise un calendar.

    y a t'il une personne ayant une solution s'il vous plait ?
    merci
    cordialement.

    vendredi 16 avril 2010 07:25

Réponses

  • Bonjour,

     

    La fonction

    Public Function InitMode(ByVal Mode As FormViewMode, Optional ByVal idPDP As String = "-1") As Boolean

     reçoit un String comme deuxième paramètre.

     

    Dans cette procédure 

    Protected Sub LinkButtonINsertAndEdit_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles LinkButtonINsertAndEdit.Click
    InitMode(FormViewMode.Edit, SaveAndGetID())
    End Sub

     vous envoyez SaveAndGetID() qui retourne un Integer :

    Public Function SaveAndGetID() As Integer

     

     

    Modifiez votre procédure pour envoyer le paramètre correcte.

     

    Cordialement,

    Alex


    Appel à contribution ! http://social.msdn.microsoft.com/Forums/fr-FR/vbasicfr/thread/bd974e0e-5519-4122-b8fc-3b998207c34f
    • Marqué comme réponse Audrey PETIT jeudi 22 avril 2010 08:58
    jeudi 22 avril 2010 07:53

Toutes les réponses

  • Bonjour,

     

    Pouvez-vous poster ici la procédure de votre code qui génère l’erreur ? Il sera plus facile de déboguer comme ça.

     

    Cordialement,

    Alex


    Appel à contribution ! http://social.msdn.microsoft.com/Forums/fr-FR/vbasicfr/thread/ff4910bf-dca4-4664-b01e-b58bd860a643
    lundi 19 avril 2010 13:57
  • bonjour,

     voici la procedure qui genere l'erreur :

    Protected Sub LinkButtonINsertAndEdit_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles LinkButtonINsertAndEdit.Click
    
    InitMode(FormViewMode.Edit, SaveAndGetID())
    
    End Sub
    
    voici le code de la page aspx: 
    <%@ Control
      Language="VB"
      AutoEventWireup="false"
      CodeFile="PDP.ascx.vb"
      Inherits="Modules_PDP" %>
    <%@ Register
      Src="~/Modules/Document.ascx"
      TagName="Document"
      TagPrefix="uc" %>
    <%@ Register
      Src="~/Modules/IntervenantPDP.ascx"
      TagName="IntervenantPDP"
      TagPrefix="uc" %>
    <%@ Register
      Src="~/Modules/AvenantPDP.ascx"
      TagName="AvenantPDP"
      TagPrefix="uc" %>
    <asp:Label
      ID="ParamidPDP"
      runat="server"
      Text="-1"
      Visible="false" />
    <asp:DetailsView
      ID="DetailsViewPDP"
      runat="server"
      AutoGenerateRows="False"
      DataSourceID="SqlDataSourcePDP"
      Width="100%" 
      DataKeyNames="IdPDP">
      <Fields>
        <asp:TemplateField
          Visible="False">
          <ItemTemplate>
            <asp:Label
              runat="server"
              ID="LabelidDocument"
              Text='<%# Eval("idDocument") %>' />
            <asp:Label
              runat="server"
              ID="LabelAllowEdit"
              Text='<%# Eval("AllowEdit") %>' />
          </ItemTemplate>
        </asp:TemplateField>
        <asp:TemplateField
          HeaderText="Entreprise"
          SortExpression="Nom">
          <InsertItemTemplate>
            <asp:TextBox
              ID="IdEntrepriseTextBox"
              runat="server"
              Text='<%# Bind("idEntreprise") %>'
              Visible="false" />
            <asp:DropDownList
              ID="DropDownListEntreprise"
              runat="server"
              AppendDataBoundItems="true"
              AutoPostBack="true"
              DataSourceID="SqlDataSourceEntreprise"
              DataTextField="Nom"
              DataValueField="idEntreprise"
              OnSelectedIndexChanged="DropDownListEntreprise_SelectedIndexChanged"
              Width="98%">
              <asp:ListItem>
              </asp:ListItem>
            </asp:DropDownList>
            <asp:RequiredFieldValidator
              ID="RequiredFieldValidator1"
              runat="server"
              ControlToValidate="DropDownListEntreprise"
              Display="Dynamic"
              ErrorMessage="Champ obligatoire" />
          </InsertItemTemplate>
          <HeaderStyle
            Width="180px" />
          <ItemTemplate>
            <asp:Label
              ID="Label4"
              runat="server"
              Text='<%# Bind("Nom") %>' />
            <asp:Label
              ID="LabelIdEntreprise"
              runat="server"
              Text='<%# Bind("idEntreprise") %>'
              Visible="false" />
          </ItemTemplate>
        </asp:TemplateField>
        <asp:TemplateField
          HeaderText="Localisation"
          SortExpression="Localisation">
          <InsertItemTemplate>
            <asp:TextBox
              ID="IdLocalisationTextBox"
              runat="server"
              Text='<%# Bind("idLocalisation") %>'
              Visible="false" />
            <asp:DropDownList
              ID="DropDownListLocalisation"
              runat="server"
              AppendDataBoundItems="true"
              AutoPostBack="true"
              DataSourceID="SqlDataSourceLocalisation"
              DataTextField="NomLocalisation"
              DataValueField="idLocalisation"
              OnSelectedIndexChanged="DropDownListLocalisation_SelectedIndexChanged"
              Width="98%">
              <asp:ListItem>
              </asp:ListItem>
            </asp:DropDownList>
            <asp:RequiredFieldValidator
              ID="RequiredFieldValidator2"
              runat="server"
              ControlToValidate="DropDownListLocalisation"
              Display="Dynamic"
              ErrorMessage="Champ obligatoire" />
          </InsertItemTemplate>
          <HeaderStyle
            Width="180px" />
          <ItemTemplate>
            <asp:Label
              ID="Label5"
              runat="server"
              Text='<%# Bind("NomLocalisation") %>' />
            <asp:Label
              ID="LabelIdLocalisation"
              runat="server"
              Text='<%# Bind("idLocalisation") %>'
              Visible="false" />
          </ItemTemplate>
        </asp:TemplateField>
        <asp:TemplateField
          HeaderText="Numero"
          SortExpression="Numero">
          <EditItemTemplate>
            <asp:TextBox
              ID="TextBoxNumero"
              runat="server"
              CssClass="textcenter"
              MaxLength="50"
              Text='<%# Bind("Numero") %>'
              Width="80px" />
            <asp:ImageButton
              ID="ImageButtonFindNumber"
              runat="server"
              OnClick="ImageButtonFindNumber_Click"
              SkinID="Find"
              ToolTip="Trouver le numéro automatiquement" />
          </EditItemTemplate>
          <InsertItemTemplate>
            <asp:TextBox
              ID="TextBoxNumero"
              runat="server"
              CssClass="textcenter"
              MaxLength="50"
              Text='<%# Bind("Numero") %>'
              Width="80px" />
            <asp:ImageButton
              ID="ImageButtonFindNumber"
              runat="server"
              OnClick="ImageButtonFindNumber_Click"
              SkinID="Find"
              ToolTip="Trouver le numéro automatiquement" />
          </InsertItemTemplate>
          <HeaderStyle
            Width="180px" />
          <ItemTemplate>
            <asp:Label
              ID="LabelNumero"
              runat="server"
              Text='<%# Bind("Numero") %>'
              Width="80px" />
          </ItemTemplate>
        </asp:TemplateField>
        <asp:TemplateField
          HeaderText="Intitule"
          SortExpression="Intitule">
          <EditItemTemplate>
            <asp:TextBox
              ID="TextBox2"
              runat="server"
              MaxLength="1000"
              Text='<%# Bind("Intitule") %>' />
          </EditItemTemplate>
          <InsertItemTemplate>
            <asp:TextBox
              ID="TextBox2"
              runat="server"
              MaxLength="1000"
              Text='<%# Bind("Intitule") %>'
              Width="98%" />
          </InsertItemTemplate>
          <HeaderStyle
            Width="180px" />
          <ItemTemplate>
            <asp:Label
              ID="Label2"
              runat="server"
              Text='<%# Bind("Intitule") %>'
              Width="98%" />
          </ItemTemplate>
        </asp:TemplateField>
        <asp:TemplateField
          HeaderText="Signature donneur d'ordre"
          SortExpression="DateSignatureDO">
          <EditItemTemplate>
            <asp:TextBox
              ID="TextBox_DateSignatureDO"
              runat="server"
              type = "datetime"
              CssClass="textcenter"
              Text='<%# Bind("DateSignatureDO") %>'
              Width="80px" />
            <asp:ImageButton
              ID="ImageButton_DateSignatureDO"
              runat="server"
              CausesValidation="false"
              OnClick="ImageButton_Calendar_Click"
              SkinID="Calendar" />
            <asp:Panel
              ID="Panel_DateSignatureDO"
              runat="server"
              Visible="false"
              Width="200px">
              <div style="margin: 7px">
                <asp:Calendar
                  ID="Calendar_DateSignatureDO"
                  runat="server"
                  OnSelectionChanged="Calendar_SelectionChanged">
                </asp:Calendar>
              </div>
            </asp:Panel>
          </EditItemTemplate>
          <InsertItemTemplate>
            <asp:TextBox
              ID="TextBox_DateSignatureDO"
              runat="server"
              CssClass="textcenter"
              type="datetime"
              Text='<%# Bind("DateSignatureDO") %>'
              Width="80px" />
            <asp:ImageButton
              ID="ImageButton_DateSignatureDO"
              runat="server"
              CausesValidation="false"
              OnClick="ImageButton_Calendar_Click"
              SkinID="Calendar" />
            <asp:Panel
              ID="Panel_DateSignatureDO"
              runat="server"
              Visible="false"
              Width="200px">
              <div style="margin: 7px">
                <asp:Calendar
                  ID="Calendar_DateSignatureDO"
                  runat="server"
                  OnSelectionChanged="Calendar_SelectionChanged">
                </asp:Calendar>
              </div>
            </asp:Panel>
          </InsertItemTemplate>
          <HeaderStyle
            Width="180px" />
          <ItemTemplate>
            <asp:Label
              ID="Label5"
              runat="server"
              Text='<%# Bind("DateSignatureDO") %>' />
          </ItemTemplate>
        </asp:TemplateField>
        <asp:TemplateField
          HeaderText="Signature entreprise exterieure"
          SortExpression="DateSignatureEE">
          <EditItemTemplate>
            <asp:TextBox
              ID="TextBox_DateSignatureEE"
              runat="server"
              CssClass="textcenter"
              type="datetime"
              Text='<%# Bind("DateSignatureEE") %>'
              Width="80px" />
            <asp:ImageButton
              ID="ImageButton_DateSignatureEE"
              runat="server"
              CausesValidation="false"
              OnClick="ImageButton_Calendar_Click"
              SkinID="Calendar" />
            <asp:Panel
              ID="Panel_DateSignatureEE"
              runat="server"
              Visible="false"
              Width="200px">
              <div style="margin: 7px">
                <asp:Calendar
                  ID="Calendar_DateSignatureEE"
                  runat="server"
                  OnSelectionChanged="Calendar_SelectionChanged">
                </asp:Calendar>
              </div>
            </asp:Panel>
          </EditItemTemplate>
          <InsertItemTemplate>
            <asp:TextBox
              ID="TextBox_DateSignatureEE"
              runat="server"
              CssClass="textcenter"
              type="datetime"
              Text='<%# Bind("DateSignatureEE") %>'
              Width="80px" />
            <asp:ImageButton
              ID="ImageButton_DateSignatureEE"
              runat="server"
              CausesValidation="false"
              OnClick="ImageButton_Calendar_Click"
              SkinID="Calendar" />
            <asp:Panel
              ID="Panel_DateSignatureEE"
              runat="server"
              Visible="false"
              Width="200px">
              <div style="margin: 7px">
                <asp:Calendar
                  ID="Calendar_DateSignatureEE"
                  runat="server"
                  OnSelectionChanged="Calendar_SelectionChanged">
                </asp:Calendar>
              </div>
            </asp:Panel>
          </InsertItemTemplate>
          <HeaderStyle
            Width="180px" />
          <ItemTemplate>
            <asp:Label
              ID="Label6"
              runat="server"
              Text='<%# Bind("DateSignatureEE") %>' />
          </ItemTemplate>
        </asp:TemplateField>
      </Fields>
    </asp:DetailsView>
    <asp:Panel
      ID="PanelI"
      Width="100%"
      runat="server"
      visible="false">
      <br />
      <table width="100%">
        <tr>
          <td style="text-align: center">
            <asp:LinkButton
              Text="Enregistrer et compléter"
              runat="server"
              ID="LinkButtonINsertAndEdit" /></td>
        </tr>
      </table>
    </asp:Panel>
    <asp:Panel
      Width="100%"
      runat="server"
      ID="PanelRW"
      Visible="false">
      <br />
      <asp:Panel
        Width="100%"
        ID="Panel2"
        runat="server"
        GroupingText="Intervenants soumis au plan de prévention">
        <div class="panelcontent">
          <uc:IntervenantPDP
            ID="IntervenantPDPUC"
            runat="server" />
        </div>
      </asp:Panel>
      <br />
      <uc:AvenantPDP
        ID="AvenantPDPUC"
        runat="server" />
      <br />
      <uc:Document
        ID="DocumentUC"
        runat="server" />
    </asp:Panel>
    <asp:SqlDataSource
      ID="SqlDataSourcePDP"
      runat="server"
      ConnectionString="<%$ ConnectionStrings:PDP %>"
      DeleteCommand="DELETE FROM [PDP] WHERE [idPDP] = @idPDP"
      InsertCommand="INSERT INTO [PDP] ([idDocument], [idEntreprise], [IdLocalisation], [Numero], [Intitule], [DateSignatureDO],[DateSignatureEE]) VALUES (@idDocument, @idEntreprise, @IdLocalisation, @Numero, @Intitule,@DateSignatureDO,@DateSignatureEE) SET @Identity = @@Identity"
      OnInserted="SqlDataSourcePDP_Inserted"
      OnInserting="SqlDataSourcePDP_Inserting"
      SelectCommand="SELECT PDP.idPDP, PDP.idDocument, PDP.Numero, PDP.Intitule, PDP.DateSignatureDO, PDP.DateSignatureEE, PDP.idEntreprise, PDP.IdLocalisation, Localisation.NomLocalisation, Entreprise.Nom, CAST(1 AS bit) AS AllowEdit FROM DonneurOrdreCommande INNER JOIN Commande ON DonneurOrdreCommande.idCommande = Commande.idCommande RIGHT OUTER JOIN PDP INNER JOIN Localisation ON PDP.IdLocalisation = Localisation.IdLocalisation INNER JOIN Entreprise ON PDP.idEntreprise = Entreprise.idEntreprise  ON Commande.idPDP = PDP.idPDP WHERE (PDP.idPDP = @idPDP) AND (DonneurOrdreCommande.idDonneurOrdre = @UserID) OR (PDP.idPDP = @idPDP) AND (DonneurOrdreCommande.idDonneurOrdre IS NULL) AND (@UserID &gt;= 0) OR (PDP.idPDP = @idPDP) AND (@UserID = 0) UNION SELECT PDP_1.idPDP, PDP_1.idDocument, PDP_1.Numero, PDP_1.Intitule, PDP_1.DateSignatureDO, PDP_1.DateSignatureEE, PDP_1.idEntreprise, Entreprise_1.Nom,PDP_1.IdLocalisation, Localisation_1.NomLocalisation, CAST(0 AS bit) AS AllowEdit FROM PDP AS PDP_1 INNER JOIN Entreprise AS Entreprise_1 ON PDP_1.idEntreprise = Entreprise_1.idEntreprise INNER JOIN LOCALISATION AS Localisation_1 ON PDP_1.IdLocalisation = Localisation_1.IdLocalisation INNER JOIN Commande AS Commande_1 ON PDP_1.idPDP = Commande_1.idPDP INNER JOIN DonneurOrdreCommande AS DonneurOrdreCommande_1 ON Commande_1.idCommande = DonneurOrdreCommande_1.idCommande WHERE (PDP_1.idPDP = @idPDP) AND (DonneurOrdreCommande_1.idDonneurOrdre &lt;&gt; @UserID) AND (NOT (DonneurOrdreCommande_1.idDonneurOrdre IS NULL)) AND (@UserID &lt;&gt; 0) OR (PDP_1.idPDP = @idPDP) AND (@UserID &lt; 0)"
      
      
      UpdateCommand="UPDATE [PDP] SET [idEntreprise] = @idEntreprise, [IdLocalisation] = @IdLocalisation, [Numero] = @Numero, [Intitule] = @Intitule, [DateSignatureDO] = @DateSignatureDO, [DateSignatureEE] = @DateSignatureEE WHERE [idPDP] = @idPDP">
      <DeleteParameters>
        <asp:Parameter
          Name="idPDP"
          Type="Int32" />
      </DeleteParameters>
      <UpdateParameters>
        <asp:Parameter
          Name="idEntreprise"
          Type="Int32" />
        <asp:Parameter
          Name="IdLocalisation" 
          Type="Int32" />
        <asp:Parameter
          Name="Numero"
          Type="char" />
        <asp:Parameter
          Name="Intitule"
          Type="char" />
        <asp:Parameter
          Name="DateSignatureDO"
          Type="DateTime" />
        <asp:Parameter
          Name="DateSignatureEE"
          Type="DateTime" />
        <asp:Parameter
          Name="idPDP"
          Type="Int32" />
      </UpdateParameters>
      <InsertParameters>
        <asp:Parameter
          Name="idDocument"
          Type="Int32" />
        <asp:Parameter
          Name="idEntreprise"
          Type="Int32" />
        <asp:Parameter
          Name="IdLocalisation" 
          Type="Int32" />
        <asp:Parameter
          Name="Numero"
          Type="char" />
        <asp:Parameter
          Name="Intitule"
          Type="char" />
        <asp:Parameter
          Name="DateSignatureDO"
          Type="DateTime" />
        <asp:Parameter
          Name="DateSignatureEE"
          Type="DateTime" />
        <asp:Parameter
          Name="Identity" />
      </InsertParameters>
      <SelectParameters>
        <asp:ControlParameter
          ControlID="ParamidPDP"
          DefaultValue="-1"
          Name="idPDP"
          PropertyName="Text"
          Type="Int32" />
        <asp:SessionParameter
          Name="UserID"
          SessionField="UserID"
          DefaultValue="-1" />
      </SelectParameters>
    </asp:SqlDataSource>
    <asp:SqlDataSource
      ID="SqlDataSourceEntreprise"
      runat="server"
      ConnectionString="<%$ ConnectionStrings:PDP %>"
      SelectCommand="SELECT [Nom], [idEntreprise] FROM [Entreprise] ORDER BY [Nom]">
    </asp:SqlDataSource>
    <asp:SqlDataSource ID="SqlDataSourceLocalisation" runat="server" 
      ConnectionString="<%$ ConnectionStrings:PDP %>" 
      SelectCommand="SELECT [IdLocalisation], [NomLocalisation] FROM [Localisation] ORDER BY [NomLocalisation]">
    </asp:SqlDataSource>
    
    
    cordialement
    mardi 20 avril 2010 14:34
  • Bonjour,

     

    Je ne trouve pas la méthode InitMode. Ou avez-vous déclaré cette méthode ? Pouvez-vous poster le code ici ?

     

    Cordialement,

    Alex


    Appel à contribution ! http://social.msdn.microsoft.com/Forums/fr-FR/vbasicfr/thread/bd974e0e-5519-4122-b8fc-3b998207c34f
    mercredi 21 avril 2010 09:36
  • <form id="aspnetForm" action="edit" enctype="application/x-www-form-urlencoded" method="post">
    <script type="text/javascript"></script> <script type="text/javascript"></script> <script type="text/javascript"></script> <noscript></noscript>
    <script src="http://i2.social.microsoft.com/Forums/GlobalResources/Scripts/omni_rsid_social.js?cver=2.13.0068.2" type="text/javascript">
    Partial Class Modules_PDP
      Inherits System.Web.UI.UserControl
    
      Public Function InitMode(ByVal Mode As FormViewMode, Optional ByVal idPDP As String = "-1") As Boolean
        InitMode = True
        On Error Resume Next
        ViewState.Clear()
    
        If IsNumeric(idPDP) Then ParamidPDP.Text = idPDP
        DetailsViewPDP.ChangeMode(Mode)
        DetailsViewPDP.DataBind()
    
        InitMode = (DetailsViewPDP.DataItemCount > 0 Or Mode = DetailsViewMode.Insert)
        If InitMode Then
          Dim idDocument As String
          Dim AllowEdit As Boolean
    
          idDocument = CType(DetailsViewPDP.FindControl("LabelidDocument"), Label).Text
          AllowEdit = CBool(CType(DetailsViewPDP.FindControl("LabelAllowEdit"), Label).Text)
    
          If Not AllowEdit And Mode = FormViewMode.Edit Then
            InitMode = InitMode(FormViewMode.ReadOnly, idPDP)
          Else
            Select Case DetailsViewPDP.CurrentMode
              Case FormViewMode.ReadOnly
                PanelRW.Visible = True
                PanelI.Visible = False
                IntervenantPDPUC.InitMode(FormViewMode.ReadOnly, idPDP)
                DocumentUC.InitMode(FormViewMode.ReadOnly, idDocument)
                AvenantPDPUC.InitMode(FormViewMode.ReadOnly, idPDP)
              Case FormViewMode.Edit
                PanelRW.Visible = True
                PanelI.Visible = False
                IntervenantPDPUC.InitMode(FormViewMode.Edit, idPDP)
                DocumentUC.InitMode(FormViewMode.Edit, idDocument)
                AvenantPDPUC.InitMode(FormViewMode.Edit, idPDP)
              Case DetailsViewMode.Insert
                PanelRW.Visible = False
                PanelI.Visible = True
            End Select
          End If
        Else
          InitMode = (DetailsViewPDP.DataItemCount > 0)
        End If
    
      End Function
    
      Public Function SaveAndGetID() As Integer
    
        If DetailsViewPDP.CurrentMode = FormViewMode.Edit Then
          DetailsViewPDP.UpdateItem(True)
        ElseIf DetailsViewPDP.CurrentMode = FormViewMode.Insert Then
          DetailsViewPDP.InsertItem(True)
        End If
        Try
          SaveAndGetID = CInt(ParamidPDP.Text)
        Catch ex As Exception
          SaveAndGetID = -1
        End Try
      End Function
    
      Public Function CurrentMode() As FormViewMode
        CurrentMode = DetailsViewPDP.CurrentMode
      End Function
    
      Public Shared Sub DeleteID(ByVal idPDP As String)
        Dim idDocument As String
        idDocument = ExecuteSQL("Select idDocument From PDP WHERE idPDP = " & idPDP).ToString
        Modules_Document.DeleteID(idDocument)
        ExecuteSQL("Delete From PDP where idPDP = " & idPDP)
      End Sub
    
      Protected Sub DropDownListEntreprise_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs)
        Dim txtEntreprise As TextBox = CType(DetailsViewPDP.FindControl("IdEntrepriseTextBox"), TextBox)
        Dim ddlEntreprise As DropDownList = CType(DetailsViewPDP.FindControl("DropDownListEntreprise"), DropDownList)
        Dim NumTextBox As TextBox = CType(DetailsViewPDP.FindControl("TextBoxNumero"), TextBox)
        txtEntreprise.Text = ddlEntreprise.SelectedValue
        If NumTextBox.Text = "" Then ImageButtonFindNumber_Click(Nothing, Nothing)
    
      End Sub
      Protected Sub DropDownListLocalisation_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs)
        Dim txtLocalisation As TextBox = CType(DetailsViewPDP.FindControl("IdLocalisationTextBox"), TextBox)
        Dim ddlLocalisation As DropDownList = CType(DetailsViewPDP.FindControl("DropDownListLocalisation"), DropDownList)
        Dim NumTextBox As TextBox = CType(DetailsViewPDP.FindControl("TextBoxNumero"), TextBox)
        txtLocalisation.Text = ddlLocalisation.SelectedValue
        If NumTextBox.Text = "" Then ImageButtonFindNumber_Click(Nothing, Nothing)
      End Sub
    
      Protected Sub SqlDataSourcePDP_Inserted(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.SqlDataSourceStatusEventArgs)
        ParamidPDP.Text = e.Command.Parameters("@Identity").Value
      End Sub
    
      Protected Sub SqlDataSourcePDP_Inserting(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.SqlDataSourceCommandEventArgs)
        e.Command.Parameters("@idDocument").Value = Outils.ExecuteSQL("Insert Into Document (Type) values ('PDP') Select @@Identity").ToString
      End Sub
    
      Public Sub SetEntreprise(ByVal idEntreprise As Integer)
        Dim ddlEntreprise As DropDownList = CType(DetailsViewPDP.FindControl("DropDownListEntreprise"), DropDownList)
        ddlEntreprise.SelectedValue = idEntreprise.ToString
        DropDownListEntreprise_SelectedIndexChanged(ddlEntreprise, Nothing)
        ddlEntreprise.Enabled = False
      End Sub
      Public Sub SetLocalisation(ByVal idLocalisation As Integer)
        Dim ddlLocalisation As DropDownList = CType(DetailsViewPDP.FindControl("DropDownListLocalisation"), DropDownList)
        ddlLocalisation.SelectedValue = idLocalisation.ToString
        DropDownListLocalisation_SelectedIndexChanged(ddlLocalisation, Nothing)
        ddlLocalisation.Enabled = False
      End Sub
    
      Sub ImageButtonFindNumber_Click(ByVal sender As Object, ByVal e As System.Web.UI.ImageClickEventArgs)
        Dim idEntreprise As Object
    
        Try
          idEntreprise = CType(DetailsViewPDP.FindControl("DropDownListEntreprise"), DropDownList).SelectedValue
    
        Catch ex As Exception
          idEntreprise = CType(DetailsViewPDP.FindControl("LabelIdEntreprise"), Label).Text
    
        End Try
        Dim NumTextBox As TextBox = CType(DetailsViewPDP.FindControl("TextBoxNumero"), TextBox)
        Dim num As Object = Nothing
        If Not IsNothing(idEntreprise) Then
          num = ExecuteSQL("Select max(Numero) From PDP Where idEntreprise = " & idEntreprise)
        End If
        If Not IsNumeric(num) Then
          num = ExecuteSQL("Select max(Numero) From PDP")
          If IsNothing(num) Then
            num = "1"
          ElseIf IsNumeric(num) Then
            num = CDec(num) + 1
          Else
            num = "(" & num.ToString & ")"
          End If
        End If
        NumTextBox.Text = num.ToString
      End Sub
    
    
      Sub ImageButton_Calendar_Click(ByVal sender As Object, ByVal e As System.Web.UI.ImageClickEventArgs)
        Outils.ImageButton_Calendar_Click(sender, e)
      End Sub
    
      Protected Sub Calendar_Init(ByVal sender As Object, ByVal e As System.EventArgs)
        Outils.Calendar_Init(sender, e)
      End Sub
    
      Protected Sub Calendar_SelectionChanged(ByVal sender As Object, ByVal e As System.EventArgs)
        Outils.Calendar_SelectionChanged(sender, e)
      End Sub
    
      Protected Sub LinkButtonINsertAndEdit_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles LinkButtonINsertAndEdit.Click
        InitMode(FormViewMode.Edit, SaveAndGetID())
      End Sub
    
    End Class
    
    </script> <noscript></noscript>
    </form>
    mercredi 21 avril 2010 11:20
  • Bonjour,

     

    La fonction

    Public Function InitMode(ByVal Mode As FormViewMode, Optional ByVal idPDP As String = "-1") As Boolean

     reçoit un String comme deuxième paramètre.

     

    Dans cette procédure 

    Protected Sub LinkButtonINsertAndEdit_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles LinkButtonINsertAndEdit.Click
    InitMode(FormViewMode.Edit, SaveAndGetID())
    End Sub

     vous envoyez SaveAndGetID() qui retourne un Integer :

    Public Function SaveAndGetID() As Integer

     

     

    Modifiez votre procédure pour envoyer le paramètre correcte.

     

    Cordialement,

    Alex


    Appel à contribution ! http://social.msdn.microsoft.com/Forums/fr-FR/vbasicfr/thread/bd974e0e-5519-4122-b8fc-3b998207c34f
    • Marqué comme réponse Audrey PETIT jeudi 22 avril 2010 08:58
    jeudi 22 avril 2010 07:53
  • bonjour,

    merci pour votre reponse, mon probleme est resolu, merci

    cordialement

    • Marqué comme réponse hamra jeudi 22 avril 2010 08:46
    • Non marqué comme réponse Audrey PETIT jeudi 22 avril 2010 08:58
    jeudi 22 avril 2010 08:46