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 9014339
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T03:29:02+00:00 2026-06-16T03:29:02+00:00

I have used below code for GridViewRowUpdating , but after click on update button,

  • 0

I have used below code for GridViewRowUpdating, but after click on update button, it takes old values.
I checked by break point for GridViewRowIpdating, and all the text boxes have old values. And new entered values do not grab.

I tried a lot in google but I could not solve the problem.

protected void GridViewDocuments_Search_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
        _DataContext = new EDMSDataContext();

        int _Docid = (int)GridViewDocuments_Search.DataKeys[e.RowIndex].Value;

        TextBox DocumentNo = (TextBox)GridViewDocuments_Search.Rows[e.RowIndex].FindControl("DocumentNo");

        TextBox title = (TextBox)GridViewDocuments_Search.Rows[e.RowIndex].FindControl("title");
        TextBox unit = (TextBox)GridViewDocuments_Search.Rows[e.RowIndex].FindControl("unit");

        TextBox originator = (TextBox)GridViewDocuments_Search.Rows[e.RowIndex].FindControl("originator");

        _DataContext.updateDoc(_Docid, DocumentNo.Text, title.Text, unit.Text, originator.Text);
        _DataContext.SubmitChanges();
        GridViewDocuments_Search.EditIndex = -1;


        var query = _DataContext.spQuickSearchDoc(txtSearchKeywords.Text);

         GridViewDocuments_Search.DataSource = query;
        GridViewDocuments_Search.DataBind();
    }

protected void GridViewDocuments_Search_RowEditing(object sender, GridViewEditEventArgs e)
{
    //var query = _DataContext.spQuickSearchDoc(txtSearchKeywords.Text);
   // GridViewDocuments_Search.DataSource = query;
    GridViewDocuments_Search.EditIndex = e.NewEditIndex;
    GridViewDocuments_Search.DataBind();
}

protected void btnSearch_Click(object sender, EventArgs e)
{

        _DataContext = new EDMSDataContext();
        var query = _DataContext.spQuickSearchDoc(txtSearchKeywords.Text);
        GridViewDocuments.Visible = false;
        GridViewDocuments_Search.Visible = true;
        GridViewDocuments_Search.DataSource = query;
        GridViewDocuments_Search.DataBind();


}

Grid view marks up:

<asp:GridView ID="GridViewDocuments_Search" runat="server" AutoGenerateColumns=False 
          Visible="False" onrowcommand="GridViewDocuments_Search_RowCommand" OnRowDeleting="GridViewDocuments_Search_RowDeleting" 
  DataKeyNames="DocID" PageSize="100" 
          onrowcancelingedit="GridViewDocuments_Search_RowCancelingEdit" 
          onrowediting="GridViewDocuments_Search_RowEditing" 
          onrowupdating="GridViewDocuments_Search_RowUpdating"  >
    <Columns>
    <asp:TemplateField HeaderText = "Details">
           <ItemTemplate>
      <asp:Button ID ="btn_Show" Text="Details" runat= "server" CommandName= "Details" CommandArgument='<%#
        Container.DataItemIndex%>' />
        </ItemTemplate>
            </asp:TemplateField>


        <asp:TemplateField HeaderText="DocNo">
            <EditItemTemplate>
                <asp:TextBox ID="DocumentNo" runat="server" Text='<%# Eval("DocumentNo") %>'></asp:TextBox>
            </EditItemTemplate>
            <ItemTemplate>
                <asp:Label ID="Label1" runat="server" Text='<%# Eval("DocumentNo") %>'></asp:Label>
            </ItemTemplate>
        </asp:TemplateField>
        <asp:TemplateField HeaderText="Title" SortExpression="title">
            <EditItemTemplate>
                <asp:TextBox ID="title" runat="server" Text='<%# Eval("title") %>'></asp:TextBox>
            </EditItemTemplate>
            <ItemTemplate>
                <asp:Label ID="Label2" runat="server" Text='<%# Eval("title") %>'></asp:Label>
            </ItemTemplate>
        </asp:TemplateField>





        <asp:TemplateField HeaderText="DocID">
            <EditItemTemplate>
                <asp:TextBox ID="TextBox1" runat="server" Text='<%# Eval("DocID") %>'></asp:TextBox>
            </EditItemTemplate>
            <ItemTemplate>
                <asp:Label ID="Label3" runat="server" Text='<%# Eval("DocID") %>'></asp:Label>
            </ItemTemplate>
        </asp:TemplateField>
        <asp:TemplateField HeaderText="Originator">
            <EditItemTemplate>
                <asp:TextBox ID="Originator" runat="server" Text='<%# Eval("Originator") %>'></asp:TextBox>
            </EditItemTemplate>
            <ItemTemplate>
                <asp:Label ID="Label4" runat="server" Text='<%# Eval("Originator") %>'></asp:Label>
            </ItemTemplate>
        </asp:TemplateField>
        <asp:TemplateField HeaderText="Unit">
            <EditItemTemplate>
                <asp:TextBox ID="Unit" runat="server" Text='<%# Eval("Unit") %>'></asp:TextBox>
            </EditItemTemplate>
            <ItemTemplate>
                <asp:Label ID="Label5" runat="server" Text='<%# Eval("Unit") %>'></asp:Label>
            </ItemTemplate>
        </asp:TemplateField>





        <asp:CommandField ShowEditButton="True" />
        <asp:CommandField ShowDeleteButton="True" />
    </Columns>
</asp:GridView>

GridViewDocuments_Search_RowCommand

protected void GridViewDocuments_Search_RowCommand(object sender, GridViewCommandEventArgs e)
{
    int rowindex = Convert.ToInt32(e.CommandArgument.ToString());
    _DataContext = new EDMSDataContext();

    int _Docid = (int)GridViewDocuments_Search.DataKeys[rowindex].Value;

    switch (e.CommandName)
    {
        case "Details":
            Response.Redirect("~/Documentfortest.aspx?DocID=" + _Docid);
            break;
        case "Delete":
            _DataContext.DeleteDoc(_Docid);
            _DataContext.SubmitChanges();

            break;

    }

    var query = _DataContext.spQuickSearchDoc(txtSearchKeywords.Text);

    GridViewDocuments_Search.DataSource = query;
    GridViewDocuments_Search.DataBind();
    //UpdatePanel1.Update();

}
  • 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-16T03:29:03+00:00Added an answer on June 16, 2026 at 3:29 am

    I think you need to move your databind code in rowcommand under Case “Delete” before break;, you are rebinding your gridview in rowcommand for every command that is fired (edit/update).

    For example:

    protected void GridViewDocuments_Search_RowCommand
    (object sender, GridViewCommandEventArgs e)
    {
        int rowindex = Convert.ToInt32(e.CommandArgument.ToString());
        _DataContext = new EDMSDataContext();
    
        int _Docid = (int)GridViewDocuments_Search.DataKeys[rowindex].Value;
    
        switch (e.CommandName)
        {
            case "Details":
                Response.Redirect("~/Documentfortest.aspx?DocID=" + _Docid);
                break;
            case "Delete":
                _DataContext.DeleteDoc(_Docid);
                _DataContext.SubmitChanges();
                 //rebind only if row is deleted
                 var query = _DataContext.spQuickSearchDoc(txtSearchKeywords.Text);
    
                 GridViewDocuments_Search.DataSource = query;
                 GridViewDocuments_Search.DataBind();
                 break;
    
        }
    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have used the code below to read rfid tag values. try { if
I have used the code below to create a button on the nav bar
I have used the below code to access iframe contents but it is not
I have used the below code but its not showing the msgbox. What is
I have used below code for delete command of GridView, but when I press
I have used below code to attach quckboook events // Subscribe to UI events...
I have some problem with my cfml website. I have used the below code
Little trouble in using css, in the below code, i have used odd and
I get this error when I run the code below. I have normally used
I have used below code for displaying multiple marker in the google map and

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.