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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T16:16:28+00:00 2026-05-23T16:16:28+00:00

I’m binding GridView like – namespace grid_edit { public partial class _Default : System.Web.UI.Page

  • 0

I’m binding GridView like –

namespace grid_edit
{
    public partial class _Default : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            SqlConnection con = new SqlConnection();
            con.ConnectionString = "Data source=HP_OWNER\\SQLEXPRESS;Database=demo;Integrated security=true";
            con.Open();
            SqlCommand cmd = new SqlCommand("select * from demo", con);
            cmd.ExecuteNonQuery();
            SqlDataAdapter mySqlAdapter = new SqlDataAdapter(cmd);
            DataSet myDataSet = new DataSet();
            mySqlAdapter.Fill(myDataSet);
            DataTable myDataTable = myDataSet.Tables[0];
            GridView1.DataSource = myDataTable;
            GridView1.DataBind();
            Session["mytable"] = myDataTable;


        }
        protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e)
        {
            GridView1.EditIndex = e.NewEditIndex;
            GridView1.DataBind();

        }       

        protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
        {
            String updatedItem = e.NewValues[0].ToString();
            String anotherUpdatedItem = e.NewValues[1].ToString();

        }

    }
}

and having Mark up like following –

<asp:GridView ID="GridView1" runat="server" AutoGenerateEditButton="True" 
            BackColor="#CCCCCC" BorderColor="#999999" BorderStyle="Solid" BorderWidth="3px" 
            CellPadding="4" CellSpacing="2" ForeColor="Black"            
        style="top: 63px; left: 309px; position: absolute; height: 183px; width: 312px; margin-top: 25px;" 
        OnRowEditing="GridView1_RowEditing" 
        OnRowCancelingEdit="GridView1_RowCancelingEdit"        
        OnRowUpdating="GridView1_RowUpdating" >
            <RowStyle BackColor="White" />
            <FooterStyle BackColor="#CCCCCC" />
            <PagerStyle BackColor="#CCCCCC" ForeColor="Black" HorizontalAlign="Left" />
            <SelectedRowStyle BackColor="#000099" Font-Bold="True" ForeColor="White" />
            <HeaderStyle BackColor="Black" Font-Bold="True" ForeColor="White" />

        </asp:GridView>

Now I would like to update the rows from the grid view but in the update event GridViewUpdateEventArgs I’m getting NewValues and OldValues empty.
How can I get the the updated values to store in the DB ? Am I doing something wrong 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-05-23T16:16:29+00:00Added an answer on May 23, 2026 at 4:16 pm

    Try to change the code as follows:

    protected void Page_Load(object sender, EventArgs e)
        {
            SqlConnection con = new SqlConnection();
            con.ConnectionString = "Data source=(local);Database=northwind;Integrated security=true";
            con.Open();
            SqlCommand cmd = new SqlCommand("select * from Categories", con);
            cmd.ExecuteNonQuery();
            SqlDataAdapter mySqlAdapter = new SqlDataAdapter(cmd);
            DataSet myDataSet = new DataSet();
            mySqlAdapter.Fill(myDataSet);
            DataTable myDataTable = myDataSet.Tables[0];
            GridView1.DataSource = myDataTable;
        if(!IsPostBack)  /// <<<<<<<<<<<<<<<<<<<<<<
            GridView1.DataBind();
            Session["mytable"] = myDataTable;
    
        }
    

    It works fine here for .NET Framework 4.

    Since you are using .NET Framework 3.0, this code does not work. I have looked at the GridView’s HandleUpdate method and found out that these collections (e.NewValues and e.OldValues) are only populated when the Gridview is bound to a DataSourceControl through DataSourceID property… A possible solution is to use the ExtractValuesFromCell method:

        cell = GridView1.Rows[e.RowIndex].Cells[1] as DataControlFieldCell;
        GridView1.Columns[1].ExtractValuesFromCell(
            e.NewValues,
            cell,
            DataControlRowState.Edit,
            true);
    

    NOTE: the Page_Load method should have the code as I suggested, i.e. the DataBind should called only once.

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

Sidebar

Related Questions

That's pretty much it. I'm using Nokogiri to scrape a web page what has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
For some reason, after submitting a string like this Jack’s Spindle from a text
Basically, what I'm trying to create is a page of div tags, each has
I've got a string that has curly quotes in it. I'd like to replace
Seemingly simple, but I cannot find anything relevant on the web. What is the
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I'm making a simple page using Google Maps API 3. My first. One marker
I have some data like this: 1 2 3 4 5 9 2 6
public static bool CheckLogin(string Username, string Password, bool AutoLogin) { bool LoginSuccessful; // Trim

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.