Обновление FormView ASP NET - PullRequest
       35

Обновление FormView ASP NET

0 голосов
/ 15 февраля 2019

Итак, у меня есть FormView, где мне нужно обновить форму, и он постоянно говорит, что мне нужно событие itemupdating.

Я вызываю обновление по нажатию кнопки

    protected void btnValidarFormulario_Click(object sender, EventArgs e)
    {
        if(Page.IsValid)
        {
            try
            {                    
                fvADefinicao.UpdateItem(true);
            }
            catch(Exception ex)
            {        
                ScriptManager.RegisterStartupScript(this, this.GetType(), "key_name", "ShowToast('Erro', 'topCenter', 'error', 'Falha na ligação à base de dados. tente novamente mais tarde', 2000);", true);
            }
            finally
            {
                ScriptManager.RegisterStartupScript(this, this.GetType(), "key_name", "ShowToast('OK', 'topCenter', 'success', 'Registo validado com sucesso', 2000); setTimeout(function(){window.location.href ='../Inicio.aspx'}, 2000);", true);
            }
        }
        else
        {
            Page.ClientScript.RegisterStartupScript(this.GetType(), "CallMyFunction", "ShowToast('Atenção', 'topCenter', 'warning', 'Preencha todos os campos com dados válidos.', 2000)", true);
        }
    }

и поСобытие sqldatasource обновлено. Я делаю еще кое-что

   protected void sdsADefinicao_Updated(object sender, SqlDataSourceStatusEventArgs e)
    {
        int id = Convert.ToInt32(e.Command.Parameters["@ReturnStatus"].Value);

        FileUpload fuAnexo = fvADefinicao.FindControl("fuAnexo") as FileUpload;

        int numFiles = fuAnexo.PostedFiles.Count;
        int index = 0;
        Ficheiro[] files = new Ficheiro[numFiles];

        foreach (HttpPostedFile file in fuAnexo.PostedFiles)
        {
            Ficheiro anexo = new Ficheiro("application/pdf", "HUTMATER");
            anexo.Nome = Path.GetFileName(file.FileName);
            using (Stream fs = file.InputStream)
            using (BinaryReader br = new BinaryReader(fs))
            {
                anexo.Dados = br.ReadBytes((Int32)fs.Length);
            }
            files[index] = anexo;
        }

        string piloto = SessionManager.Nome;
        Ficheiro.Upload(id, piloto, files); // Guarda anexos do formulario na base de dados            
    }


    <asp:SqlDataSource
                ID="sdsADefinicao"
                runat="server"
                ConnectionString="<%$ ConnectionStrings:ValidacaoFormas_ConnectionString %>"
                UpdateCommand="sp_UPDATE_ADefinicao_Extrusao"
                UpdateCommandType="StoredProcedure"                    
                OnUpdated="sdsADefinicao_Updated"
                SelectCommandType="StoredProcedure"
                SelectCommand="sp_SELECT_ADefinicao">

                <SelectParameters>
                    <asp:ControlParameter ControlID="hdfRegistoID" Name="RegistoID" Type="Int32" />
                </SelectParameters>

                <UpdateParameters>
                    <asp:Parameter Name="Base_Cru" Type="String" />
                    <asp:Parameter Name="Linha_Cru" Type="String" />
                    <asp:Parameter Name="Marcacao_Continua_Cru" Type="String" />
                    <asp:Parameter Name="Diametro_Cru" Type="Decimal" />
                    <asp:Parameter Name="Espessura_Cru" Type="Decimal" />
                    <asp:Parameter Name="Comprimento_Cru" Type="Decimal" />
                    <asp:Parameter Name="ReturnStatus" Type="Int32" Direction="Output" />
                    <asp:ControlParameter ControlID="hdfRegistoID" Name="RegistoID" Type="Int32" Direction="Output" />
                </UpdateParameters>
            </asp:SqlDataSource>

Я даже попытался создать событие onItemUpdating без чего-либо и все равно выдал мне ту же ошибку, что событие itemupdating не было обработано.Я могу сделать вставку в formview, просто используя sqldatasource без вставки из событий formview.Почему я не могу сделать то же самое при обновлении в представлении формы?

<asp:FormView 
    runat="server" 
    ID="fvADefinicao" 
    DataKeyNames="ID_Registo" 
    DefaultMode="Edit" 
    HorizontalAlign="Center" 
    Style="width: 100%; max-width: 1200px;">
                <EditItemTemplate>
...