Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7804567
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T01:57:29+00:00 2026-06-02T01:57:29+00:00

I have a problem, when i delete a item for example, it deletes from

  • 0

I have a problem, when i delete a item for example, it deletes from the database, do well the bindGridView(), but dont refresh the screen… what i’m doing wrong?

The other problem is for example when i delete a item i want to show a sucess message, but isnt refreshing with the update panel too..

is the same problem
This is my code:

<asp:UpdatePanel ID="UpdatePanelListaUsers" runat="server" UpdateMode="Always">
                            <ContentTemplate>
                                <asp:GridView ID="gridviewListUsers" runat="server" AutoGenerateColumns="false" OnRowCreated="OnRowCreated"
                                AllowPaging="True" AllowSorting="True" OnSorting="OnSort" DataKeyNames="Id" PageSize="2"
                                CssClass="cssTable" BorderWidth="0" Width="900px" AlternatingRowStyle-CssClass="alternate-row"
                                OnRowCommand="gridviewListUsers_RowCommand" 
                                EmptyDataText="Não existe utilizadores..." 
                                    onpageindexchanging="gridviewListUsers_PageIndexChanging">
                                <PagerStyle HorizontalAlign="Right" Font-Bold="true" Font-Size="X-Large" ForeColor="black" />
                                <PagerSettings Mode="Numeric" />
                                <Columns>
                                    <asp:BoundField HeaderStyle-CssClass="table-header-repeat line-left minwidth-1" HeaderText="Nome"
                                        DataField="Name" SortExpression="Name" />
                                    <asp:BoundField HeaderStyle-CssClass="table-header-repeat line-left minwidth-1" HeaderText="Username"
                                        DataField="Username" SortExpression="Username" />
                                    <asp:BoundField HeaderStyle-CssClass="table-header-repeat line-left" HeaderText="Email"
                                        DataField="Email" SortExpression="Email" />
                                    <asp:TemplateField ItemStyle-CssClass="options-width" HeaderStyle-CssClass="table-header-options line-left">
                                        <HeaderTemplate>
                                            <a href="">Opções</a></HeaderTemplate>
                                        <ItemTemplate>
                                            <asp:LinkButton ID="lnkEdit" CommandArgument='<%# ((GridViewRow) Container).RowIndex %>' CssClass="icon-1 info-tooltip"
                                                CommandName="edit" ToolTip="Editar" runat="server"></asp:LinkButton>
                                            <asp:LinkButton ID="lnkDelete" CommandArgument='<%# ((GridViewRow) Container).RowIndex %>' CssClass="icon-2 info-tooltip"
                                                CommandName="delete" ToolTip="Remover" runat="server"></asp:LinkButton>
                                        </ItemTemplate>
                                    </asp:TemplateField>
                                </Columns>
                            </asp:GridView>
                            </ContentTemplate>
                            </asp:UpdatePanel>

and

<asp:UpdatePanel ID="UpdatePanelMensagens" runat="server" UpdateMode="Always">
                            <ContentTemplate>
                            <asp:Panel ID="pnlMessageRed" Visible="false" runat="server">
                                <!--  start message-red -->
                                <div id="message-red">
                                    <table border="0" width="100%" cellpadding="0" cellspacing="0">
                                        <tr>
                                            <td class="red-left">
                                                Erro. Ficou gravado a informação do erro, tente novamente
                                            </td>
                                            <td class="red-right">
                                                <a class="close-red">
                                                    <img src="../images/table/icon_close_red.gif" alt="" /></a>
                                            </td>
                                        </tr>
                                    </table>
                                </div>
                                <!--  end message-red -->
                            </asp:Panel>
                            <asp:Panel ID="pnlMessageBlue" Visible="false" runat="server">
                                <!--  start message-blue -->
                                <div id="message-blue">
                                    <table border="0" width="100%" cellpadding="0" cellspacing="0">
                                        <tr>
                                            <td class="blue-left">
                                                <asp:Label ID="lblSucesso" runat="server"></asp:Label>
                                            </td>
                                            <td class="blue-right">
                                                <a class="close-blue">
                                                    <img src="../images/table/icon_close_blue.gif" alt="" /></a>
                                            </td>
                                        </tr>
                                    </table>
                                </div>
                                <!--  end message-blue -->
                            </asp:Panel>
                            </ContentTemplate>
                            </asp:UpdatePanel>

this is the gridview code

private void bindGridView()
    {
        String strSort = String.Empty;
        if (null != m_strSortExp &&
            String.Empty != m_strSortExp)
        {
            strSort = String.Format("{0} {1}", m_strSortExp, (m_SortDirection == SortDirection.Descending) ? "DESC" : "ASC");
        }
        DataView dv = new DataView(m_dsUsers.Tables[0], String.Empty, strSort, DataViewRowState.CurrentRows);
        gridviewListUsers.DataSource = dv;
        gridviewListUsers.DataBind();
        UpdatePanelListaUsers.Update();
    }

protected void OnSort(object sender, GridViewSortEventArgs e)
    {
        // There seems to be a bug in GridView sorting implementation. Value of
        // SortDirection is always set to "Ascending". Now we will have to play
        // little trick here to switch the direction ourselves.
        if (String.Empty != m_strSortExp)
        {
            if (String.Compare(e.SortExpression, m_strSortExp, true) == 0)
            {
                m_SortDirection =
                    (m_SortDirection == SortDirection.Ascending) ? SortDirection.Descending : SortDirection.Ascending;
            }
        }
        ViewState["_Direction_"] = m_SortDirection;
        ViewState["_SortExp_"] = m_strSortExp = e.SortExpression;
        this.bindGridView();
    }

    void AddSortImage(GridViewRow headerRow)
    {
        Int32 iCol = GetSortColumnIndex(m_strSortExp);
        if (-1 == iCol)
        {
            return;
        }
        // Create the sorting image based on the sort direction.
        Image sortImage = new Image();
        if (SortDirection.Ascending == m_SortDirection)
        {
            sortImage.ImageUrl = "~/images/table/dwn.gif";
            sortImage.AlternateText = "Ordem Ascendente";
        }
        else
        {
            sortImage.ImageUrl = "~/images/table/up.gif";
            sortImage.AlternateText = "Ordem Descendente";
        }

        // Add the image to the appropriate header cell.
        headerRow.Cells[iCol].Controls.Add(sortImage);
    }

    // This is a helper method used to determine the index of the
    // column being sorted. If no column is being sorted, -1 is returned.
    int GetSortColumnIndex(String strCol)
    {
        foreach (DataControlField field in gridviewListUsers.Columns)
        {
            if (field.SortExpression == strCol)
            {
                return gridviewListUsers.Columns.IndexOf(field);
            }
        }

        return -1;
    }

    protected void gridviewListUsers_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        if (e.CommandName == "delete")
        {
            try
            {
                //obter o id
                int index = int.Parse((string)e.CommandArgument);
                string key = gridviewListUsers.DataKeys[index]["Id"].ToString();

                //apagar o utilizador
                Project_BLL.Users.RemoveUser(Convert.ToInt32(key));

                //mensagem de sucesso
                pnlMessageRed.Visible = false;
                pnlMessageBlue.Visible = true;
                lblSucesso.Text = "Utilizador adicionado com sucesso. A reencaminhar...";

                //força o update dos users, e nao da cache
                bindGridView();

                GridViewRow row = (GridViewRow)(((LinkButton)e.CommandSource).NamingContainer);
                LinkButton lb = (LinkButton)row.FindControl("lnkDelete");
                if (lb != null)
                {
                    ScriptManager.GetCurrent(this).RegisterAsyncPostBackControl(lb);
                }

                ScriptManager.RegisterStartupScript(this, this.GetType(), "alertUser", "alert('deleted');", true);

            }
            catch (Exception er)
            {
                pnlMessageRed.Visible = true;
                pnlMessageBlue.Visible = false;
            }
        }

        else if (e.CommandName == "edit")
        {
            try
            {
                int index = int.Parse((string)e.CommandArgument);
                string key = gridviewListUsers.DataKeys[index]["Id"].ToString();

                Response.Redirect("EditarUtilizador.aspx?id=" + key);
            }
            catch (Exception)
            {
                pnlMessageRed.Visible = true;
                pnlMessageBlue.Visible = false;
            }
        }

    }

    protected void gridviewListUsers_PageIndexChanging(object sender, GridViewPageEventArgs e)
    {
        gridviewListUsers.PageIndex = e.NewPageIndex;
        gridviewListUsers.SelectedIndex = -1;
        bindGridView(); // Call bind here
    }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T01:57:32+00:00Added an answer on June 2, 2026 at 1:57 am

    Just changed the CommandName to myEdit and myDelete (like Ashwini Verma suggest before), and now it works.

    Then i google it to find why, and seems that that words are reserved

    http://www.mindfiresolutions.com/Issue-with-OnRowCommand-event-of-GridView-while-using-reserve-words-in-CommandName-property-935.php

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

The problem i have is i could DELETE but then when i hit refresh
I write this code for delete from repeater,but I have a problem. when I
i have problem use link_to_remote link_to_remote document example say link_to_remote Delete this post, :update
I have tried to delete an item from a string divided with commas: var
i have this problem: ms-access could not delete and i found a potential solution
I have a problem with JPA (EclipseLink). I am not able to delete a
I have problem creating new instance of excel 2007 using VBA (from Access 2002).
I made my first jQuery plugin attempt, but I have this problem/bug which I
I have problem with deleting rows from table. I have a class for cell
I have a problem when parsing xml from the internet. The parser doesn't return

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.