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

  • SEARCH
  • Home
  • 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 8452589
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T11:32:21+00:00 2026-06-10T11:32:21+00:00

I already spend 2 days trying to solve this issue but no luck on

  • 0

I already spend 2 days trying to solve this issue but no luck on how to solve this. I have a GridView to display data from the database then it also have functionality to modify and delete. This is the current ASP code for my GridView:

<asp:GridView ID="dgvSortKey" runat="server" AllowSorting="True" OnRowDataBound="gv_drb"
                AutoGenerateColumns="False" AllowPaging="True" BackColor="White" BorderColor="#336666"
                BorderStyle="Double" BorderWidth="3px" CellPadding="4" GridLines="Horizontal"
                Height="73px" AutoGenerateEditButton="True" OnRowEditing="dgvSortKey_RowEditing"
                OnRowUpdating="dgvSortKey_RowUpdating" OnRowCancelingEdit="dgvSortKey_RowCancelingEdit"
                OnSelectedIndexChanging="dgvSortKey_SelectedIndexChanging" OnPageIndexChanged="dgvSortKey_PageIndexChanged"
                OnPageIndexChanging="dgvSortKey_PageIndexChanging" OnRowCommand="dgvSortKey_RowCommand"
                OnRowDeleted="dgvSortKey_RowDeleted" OnRowUpdated="dgvSortKey_RowUpdated" Width="561px"
                PageSize="15" DataKeyNames="KeyCode,KeyDescription">
                <FooterStyle BackColor="White" ForeColor="#333333" />
                <RowStyle BackColor="White" ForeColor="#333333" />
                <PagerStyle BackColor="#336666" ForeColor="White" HorizontalAlign="Center" />
                <SelectedRowStyle BackColor="#339966" Font-Bold="True" ForeColor="White" />
                <HeaderStyle BackColor="#336666" Font-Bold="True" ForeColor="White" HorizontalAlign="Center" />
                <AlternatingRowStyle BackColor="LightCyan" />
                <Columns>
                    <asp:TemplateField HeaderText="">
                        <ItemTemplate>
                            <asp:LinkButton ID="lnkdelete" runat="server" OnClick="lnkdelete_Click">Delete</asp:LinkButton>
                        </ItemTemplate>
                    </asp:TemplateField>
                    <asp:TemplateField HeaderText="Instruction Key Code">
                        <ItemTemplate>
                            <asp:Label ID="lblValKeyCode" runat="server" Text='<%#System.Web.HttpUtility.HtmlEncode((string)Eval("KeyCode")) %>'></asp:Label>
                        </ItemTemplate>
                        <EditItemTemplate>
                            <asp:TextBox ID="txtValKeyCode" runat="server" Text='<%#Bind("KeyCode") %>' MaxLength="10"
                                CausesValidation="false"></asp:TextBox>
                        </EditItemTemplate>
                        <ItemStyle HorizontalAlign="Center" VerticalAlign="Middle" CssClass="GvBorderGreen" />
                    </asp:TemplateField>
                    <asp:TemplateField HeaderText="Description">
                        <ItemTemplate>
                            <asp:Label ID="lblValKeyDescription" runat="server" Text='<%#System.Web.HttpUtility.HtmlEncode((string)Eval("KeyDescription")) %>'></asp:Label>
                        </ItemTemplate>
                        <EditItemTemplate>
                            <asp:TextBox ID="txtValKeyDescription" runat="server" Text='<%#Bind("KeyDescription") %>'
                                Width="300" MaxLength="20" CausesValidation="false"></asp:TextBox>
                        </EditItemTemplate>
                        <ItemStyle CssClass="GvBorderGreen" />
                    </asp:TemplateField>
                </Columns>
            </asp:GridView>

The problem is I can’t update a certain record after click the Update Button, please see the image below:

enter image description here

When I’m in debug mode, it does not pass on OnRowUpdating event instead it passes to OnRowEditing. One thing that it makes me surprise is that when it fires to OnRowCommand, the CommandName set to “Edit” when Update Button is clicked. Please see the image below:

enter image description here

BTW this the Code Behind.

protected void dgvSortKey_RowUpdating(object sender, GridViewUpdateEventArgs e)
    {
        //Currently Unreachable code due to unknown reason. RowUpdating not trigger even clicking Update Button in the GridView
        // this.dvDetialContent.Visible = true;
        List<SqlDbParameter> list = new List<SqlDbParameter>();

        TextBox txtValKeyDescription = dgvSortKey.Rows[e.RowIndex].FindControl("txtValKeyDescription") as TextBox;
        TextBox txtValKeyCode = dgvSortKey.Rows[e.RowIndex].FindControl("txtValKeyCode") as TextBox;

        if (string.IsNullOrEmpty(txtValKeyCode.Text) || string.IsNullOrEmpty(txtValKeyDescription.Text))
        {
            string alert = "alert('Instruction KeyCode or KeyDecription should not be empty');";
            ScriptManager.RegisterStartupScript(this, this.GetType(), "scripting", alert, true);
        }
        else
        {
            //Trace.Write("txtKeyCode", HttpUtility.HtmlDecode(txtKeyCode.Text));
            //Trace.Write("txtKeyDescription", txtKeyDescription.Text);
            //Trace.Write("txtValKeyCode", txtValKeyCode.Text);
            //Trace.Write("txtValKeyDescription", txtValKeyDescription.Text);
            list.Add(new SqlDbParameter("@oldcode", HttpUtility.HtmlDecode(txtKeyCode.Text)));
            list.Add(new SqlDbParameter("@oldname", HttpUtility.HtmlDecode(txtKeyDescription.Text)));
            list.Add(new SqlDbParameter("@newcode", HttpUtility.HtmlDecode(txtValKeyCode.Text)));
            list.Add(new SqlDbParameter("@newname", HttpUtility.HtmlDecode(txtValKeyDescription.Text)));
            try
            {
                int result = CoreUtility.ExecuteNonQuery("update InstructionKey set KeyCode=@newcode, KeyDescription=@newname where KeyCode = @oldcode and KeyDescription = @oldname", list);
                //Trace.Write("ResultValue", result.ToString());
            }
            catch (Exception ex)
            {
                string alert = "alert('Instruction KeyCode should not be duplicate');";
                ScriptManager.RegisterStartupScript(this, this.GetType(), "scripting2", alert, true);
            }
        }

        dgvSortKey.EditIndex = -1;
        imgbtnFilter_Click(null, null);

        this.txtKeyCode.Text = "";
        this.txtKeyDescription.Text = "";

    }
    protected void dgvSortKey_RowEditing(object sender, GridViewEditEventArgs e)
    {
        // this.dvDetialContent.Visible = true;
        //if (ViewState["updateFlag"] == null)
        //{
            //ViewState["editFlag"] = "forEdit";
            //ViewState["editIndex"] = e.NewEditIndex;
            dgvSortKey.EditIndex = e.NewEditIndex;
            Label lblValKeyDescription = dgvSortKey.Rows[e.NewEditIndex].FindControl("lblValKeyDescription") as Label;
            Label lblValKeyCode = dgvSortKey.Rows[e.NewEditIndex].FindControl("lblValKeyCode") as Label;
            this.txtKeyCode.Text = lblValKeyCode.Text;
            this.txtKeyDescription.Text = lblValKeyDescription.Text;
            imgbtnFilter_Click(null, null);
        //}
        //else
        //{
            //RowUpdate((int)ViewState["editIndex"]);
            //ViewState.Remove("updateFlag");
            //ViewState.Remove("editFlag");
            //ViewState.Remove("editIndex");
        //}
    }
    protected void dgvSortKey_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e)
    {
        dgvSortKey.EditIndex = -1;
        imgbtnFilter_Click(null, null);
    }
    protected void dgvSortKey_SelectedIndexChanging(object sender, GridViewSelectEventArgs e)
    {
        this.dvDetialContent.Visible = true;
        Label lblValKeyDescription = dgvSortKey.Rows[e.NewSelectedIndex].FindControl("lblValKeyDescription") as Label;
        Label lblValKeyCode = dgvSortKey.Rows[e.NewSelectedIndex].FindControl("lblValKeyCode") as Label;

        this.txtKeyCode.Text = lblValKeyCode.Text;
        this.txtKeyDescription.Text = lblValKeyDescription.Text;
    }
    protected void dgvSortKey_PageIndexChanged(object sender, EventArgs e)
    {

    }
    protected void dgvSortKey_PageIndexChanging(object sender, GridViewPageEventArgs e)
    {
        dgvSortKey.PageIndex = e.NewPageIndex;
        imgbtnFilter_Click(null, null);
    }
    protected void dgvSortKey_RowUpdated(object sender, GridViewUpdatedEventArgs e)
    {

    }
    protected void dgvSortKey_RowDeleting(object sender, GridViewDeleteEventArgs e)
    {
        String jsScript = "";
        jsScript += "var answer=confirm('Delete this Instruction Key?');\n";
        jsScript += "if (!answer){\n";
        jsScript += " document.getElementById('ctl00_cthContent_hdDelete').Value = 'DELETE';\n";
        jsScript += "}\n";

        //return;
        ScriptManager.RegisterStartupScript(this, this.GetType(), "script", jsScript, true);

        List<SqlDbParameter> list = new List<SqlDbParameter>();

        Label lblValKeyCode = dgvSortKey.Rows[e.RowIndex].FindControl("lblValKeyCode") as Label;
        Label lblValKeyDescription = dgvSortKey.Rows[e.RowIndex].FindControl("lblValKeyDescription") as Label;
        list.Add(new SqlDbParameter("@code", lblValKeyCode.Text));
        list.Add(new SqlDbParameter("@name", lblValKeyDescription.Text));

        CoreUtility.ExecuteNonQuery("DELETE FROM [InstructionKey] WHERE KeyCode=@code and KeyDescription=@name;", list);
        Initial();
        this.dvDetialContent.Visible = false;
        dgvSortKey.EditIndex = -1;
        imgbtnFilter_Click(null, null);
    }
    protected void dgvSortKey_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        string id = e.CommandName;
    }
    protected void dgvSortKey_RowDeleted(object sender, GridViewDeletedEventArgs e)
    {

    }
    protected void gv_drb(object sender, GridViewRowEventArgs e)// 
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            LinkButton lnkbtnresult = (LinkButton)e.Row.FindControl("lnkdelete");
            //raising javascript confirmationbox whenver user clicks on link button
            lnkbtnresult.Attributes.Add("onclick", "javascript:return ConfirmationBox()");
        }
    }
  • 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-10T11:32:22+00:00Added an answer on June 10, 2026 at 11:32 am

    While I have not figured out the bug, there is a workaround you may want to try.
    Since the autogenerated edit button is giving you trouble, why not generate it yourself?

    Like this:

    <asp:TemplateField HeaderText="">
        <ItemTemplate>
            <asp:LinkButton ID="lnkedit" runat="server" CommandName="Edit">Edit</asp:LinkButton>
        </ItemTemplate>
        <EditItemTemplate>
            <asp:LinkButton ID="lnkedit" runat="server" CommandName="Update">Update</asp:LinkButton>
            <asp:LinkButton ID="lnkedit" runat="server" CommandName="Cancel">Cancel</asp:LinkButton>
        </EditItemTemplate> 
    </asp:TemplateField>
    

    And handle it in your code behind:

      void dgvSortKey_RowCommand(Object sender, GridViewCommandEventArgs e)
      {
        // If multiple buttons are used in a GridView control, use the
        // CommandName property to determine which button was clicked.
        if(e.CommandName=="Update")
        {
    
        }
      }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I know several posts already exist about this issue but I spent days to
I can not compile, this program is giving me errors. I have already spend
I have a problem with php header redirect. I already spent hours trying to
I could send mail from my Activity when i have already configured with any
My issue is simple. I have already implemented a tab system, and I'd probably
I'm trying to speed up SELECT queries in MySQL tables which already have some
Revised (clarified question) I've spent a few days already trying to figure out how
Im already 5 days trying to make jquery drag and drop with asp.net c#
must be some thing simply resolving, but as a beginner, i've already spend 2
I know this is a low-level question but, not being a database person, I

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.