Web Form do not update data when I click in update button

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • markevis
    New Member
    • Apr 2014
    • 1

    #1

    Web Form do not update data when I click in update button

    My web applicatin has two web forms using Master Page that access data tables in SqlServer database:

    1 - Autoridade.aspx that shows data and search them

    2- Autoridade_Atua lizar.aspx that updates data in table lideranca

    Autoridade.aspx has a GridView that show data and uses asp:HyperLinkFi eld to redirect to Autoridade_Atua lizar.aspx:

    Code:
    <asp:GridView ID="gwDados" runat="server" AutoGenerateColumns="False" EmptyDataText="Não Existem Autoridades Cadastradas..."> <Columns> <asp:BoundField DataField="id" HeaderText="ID" /> <asp:BoundField DataField="nome" HeaderText="Nome" /> <asp:BoundField DataField="partido" HeaderText="Partido" /> <asp:BoundField DataField="aliado" HeaderText="Aliado" /> <asp:BoundField DataField="cargo" HeaderText="Cargo" /> <asp:BoundField DataField="lotacao" HeaderText="Lotação" /> <asp:BoundField DataField="atuacao" HeaderText="Atuação" /> <asp:HyperLinkField DataNavigateUrlFormatString="Autoridade_Atualizar. aspx?id={0}" Text="Editar" DataNavigateUrlFields="id" /> </Columns> </asp:GridView>
    When I exchange the values of the DropDownLists fields and click on Update Button of the Form do not alter the data on gridview.

    Code:
    asp:Panel runat="server" ID="pnlUpdate" Visible="true"> <h1>Atualizar Autoridade</h1> <ul> <li> <asp:Label ID="CodAutoridade" runat="server" Text="Cód. Autoridade"></asp:Label> <asp:TextBox ID="tbCodAutoridade" Text="2013" Enabled="false" CssClass="radiusInput disable" runat="server" Width="546px"></asp:TextBox> </li> <li> <asp:Label Text="Nome" ID="label1" runat="server" Width="88px"></asp:Label> <asp:TextBox ID="tbNome" Text="" CssClass="radiusInput" runat="server" Width="654px" Height="16px"></asp:TextBox> </li> <li> <asp:Label ID="Cargo" runat="server" Text="Cargo"></asp:Label> <asp:DropDownList ID="ddlcargo" DataTextField="carg_cargo" DataValueField="carg_cd_cargo" CssClass="radiusInput" runat="server" Width="454px"></asp:DropDownList> </li> <li> <asp:Label ID="Partido" runat="server" Text="Partido"></asp:Label> <asp:DropDownList ID="ddlpartido" DataTextField="part_sigla" DataValueField="part_cd_partido" CssClass="radiusInput" runat="server" Width="254px"></asp:DropDownList> </li> <li>
    Code:
    protected void bntAtualizar_Click(object sender, EventArgs e)
    {
    this.OnUpdate();
    }
    
    private void OnUpdate()
    {
    
    mdc = new ModelDataContext();
    try
    {
    lid_lideranca lideranca = mdc.lid_liderancas.First(aut => aut.lid_cd_lideranca == int.Parse(tbCodAutoridade.Text.Trim()));
    
    
    tbNome.Text = lideranca.lid_nome;
    ddlcargo.SelectedIndex = ddlcargo.Items.IndexOf(ddlcargo.Items.FindByText(l ideranca.lid_cd_partido.ToString()));
    ddlpartido.SelectedIndex = ddlpartido.Items.IndexOf(ddlpartido.Items.FindByTe xt(lideranca.lid_cd_partido.ToString()));
    tbDescricao.Text = lideranca.lid_cargo2;
    tbemail.Text = lideranca.lid_email;
    tbfacebook.Text = lideranca.lid_facebook;
    tbtwitter.Text = lideranca.lid_twitter;
    tbendercomercial.Text = lideranca.lid_endereco_comercial;
    tbenderesidencial.Text = lideranca.lid_endereco_residencial;
    tbfonecelular.Text = lideranca.lid_fone_celular;
    tbfoneresidencial.Text = lideranca.lid_fone_residencial;
    tbfonecomercial.Text = lideranca.lid_fone_comercial;
    ddlmunicipio.SelectedIndex = ddlmunicipio.Items.IndexOf(ddlmunicipio.Items.Find ByText(lideranca.lid_cd_cidade_atuacao.ToString()) );
    ddlbasealiada.SelectedIndex = ddlbasealiada.Items.IndexOf(ddlbasealiada.Items.Fi ndByText(lideranca.lid_cd_base_aliada.ToString())) ;
    ddlorgao.SelectedIndex = ddlorgao.Items.IndexOf(ddlorgao.Items.FindByText(l ideranca.lid_cd_orgao.ToString()));
    
    mdc.SubmitChanges();
    Response.Redirect("Autoridade.aspx");
    }
    catch (Exception)
    {
    
    }
    finally
    {
    mdc.Dispose();
    }
    
    }
  • pawankumarindia
    New Member
    • Apr 2014
    • 2

    #2
    you have simply debug the application step by step using the "F10" key and in between you can get the issue area. best of luck.

    kumar
    Last edited by Rabbit; Apr 30 '14, 03:35 PM. Reason: Link removed per forum policy.

    Comment

    Working...