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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T02:57:06+00:00 2026-05-26T02:57:06+00:00

So I am having an issue with doing an update in a Gridview during

  • 0

So I am having an issue with doing an update in a Gridview during an OnRowUpdating event.

What I am trying to do is set the UpdateCommand in an SqlDataSource then update using that command. The event is firing okay, but when the event is done it appears that the row never updates.

C#:

protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
    SqlDataSource1.UpdateCommand = "UPDATE A_Table SET Something = @AValue WHERE ID = " + e.RowIndex;

    SqlDataSource1.Update();
}

Edit: Re-wrote my example update command…it is really an update command, not a select command haha.

  • 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-26T02:57:06+00:00Added an answer on May 26, 2026 at 2:57 am

    The other answers here are VERY correct in pointing out the issue with your UpdateCommand.

    As I mentioned in the comment earlier, I’ll just point out that this is a bit easier than what you have there. When using a GridView with a SQLDataSource, alot of the work is done for you as long as you set up correctly.

    First off, define your UpdateCommand in the markup for the SQLDataSource, like this:

    <asp:SqlDataSource ID="SqlDataSource1" runat="server" 
        ConnectionString="Your Connection String Here" 
        ProviderName="System.Data.SqlClient" 
        SelectCommand="SELECT ColPK, ColA, ColB, ColC FROM Table_Name" 
        UpdateCommand="UPDATE Table_Name 
                       SET ColA=@ColA,  ColB=@ColB, ColC=@ColC, 
                       WHERE ColPK=@ColPK">
    </asp:SqlDataSource>
    

    (ColPK would be the primary key of the table you’re updating)

    Then, you can set “AutoGenerateEditButton” to true in your GridView markup and, poof! You can update the GridView (without having to do anything in code behind).

    <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" 
        AutoGenerateEditButton="True" DataKeyNames="ColPK" 
        DataSourceID="SqlDataSource1">
        <Columns>
            <asp:BoundField DataField="ColPK" HeaderText="Column PK" 
                SortExpression="ColA" ReadOnly="True" />
            <asp:BoundField DataField="ColA" HeaderText="Column A" 
                SortExpression="ColA" />
            <asp:BoundField DataField="ColB" HeaderText="Column B" 
                SortExpression="ColB" />
            <asp:BoundField DataField="ColC" HeaderText="Column C" 
                SortExpression="ColC" />
        </Columns>
    </asp:GridView>
    

    Now, you can still handle the OnRowUpdating event in your code if you need to do extra processing, or cancel the Update based on some logic, etc. But the basic Update functionality is pretty much for free!

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

Sidebar

Related Questions

Having an issue with random individuals trying to access an intranet site with a
Having an issue here that I have tried everything I can think of but
The issue I'm having is issue with is I'm trying to get the paintComponent
I'm having an issue with a query that currently uses LEFT JOIN weblog_data AS
I'm having an issue with a standard ASP.NET page that has a TextBox and
I'm having an issue with an event handler in SharePoint. I have a list
I'm still very new to codeigniter. The issue i'm having is that the file
hello fellow java developers. I'm having a very strange issue. I'm trying to read
EDIT: After fixing a few issues, the bigger issue that I am having is
Having a weird issue. I'm new to Macs and have a windows VM that

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.