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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T09:58:10+00:00 2026-06-11T09:58:10+00:00

I have a gridview that has databound items. it is bound to a SQLDATASOURCE.

  • 0

I have a gridview that has databound items. it is bound to a SQLDATASOURCE. The default Edit, Update works fine, however, i wanted to perform a query too when user updates the row.
Here is my aspx

  <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataKeyNames="Customer_id"
        DataSourceID="SqlDataSource1" 
        EmptyDataText="There are no data records to display." AllowPaging="True" 
        AllowSorting="True" CellPadding="4" ForeColor="#333333" GridLines="Horizontal" 
        PageSize="5" Width="873px"  OnRowCommand = "RunCustomMethod" >
        <AlternatingRowStyle BackColor="White" ForeColor="#284775" />
        <Columns>
            <asp:TemplateField>
                <EditItemTemplate>
                    <asp:LinkButton ID="LinkButton1" runat="server" CausesValidation="True"
                        CommandName="myCustomUpdateMethod" Text="Update" CommandArgument = '<%# Eval("Customer_ID") %>'
                        onclientclick="return Confirm ('Are You Sure You Want To Make These Changes?')"></asp:LinkButton>
                    &nbsp;<asp:LinkButton ID="LinkButton2" runat="server" CausesValidation="False" 
                        CommandName="Cancel" Text="Cancel"></asp:LinkButton>
                </EditItemTemplate>
                <ItemTemplate>
                    <asp:LinkButton ID="LinkButton1" runat="server" CausesValidation="False" 
                        CommandName="Edit" Text="Edit" ></asp:LinkButton>
                    &nbsp;
                    <asp:LinkButton ID="LinkButton2" runat="server" CausesValidation="False" 
                        CommandName="Select" Text="Select"></asp:LinkButton>
                    &nbsp;
                 </ItemTemplate>
            </asp:TemplateField>
            <asp:BoundField DataField="Customer_id" HeaderText="Customer_id" ReadOnly="True"
                SortExpression="Customer_id" InsertVisible="False" />
            <asp:TemplateField HeaderText="Customer_Name" SortExpression="Customer_Name">
                <EditItemTemplate>
                    <asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("Customer_Name") %>'></asp:TextBox>
                </EditItemTemplate>
                <ItemTemplate>
                    <asp:Label ID="Label1" runat="server" Text='<%# Bind("Customer_Name") %>'></asp:Label>
                </ItemTemplate>
            </asp:TemplateField>

        </Columns>

    </asp:GridView>

And here is my c# Code

  protected void RunCustomMethod(object sender, GridViewCommandEventArgs e)
        {
                // Custom Method To Update Row
            if (e.CommandName == "myCustomUpdateMethod")
            {
                int customerID = Convert.ToInt32(e.CommandArgument);

                   SqlConnection conn = new SqlConnection(SqlDataSource1.ConnectionString);
                SqlCommand Cmd = new SqlCommand();

                try
                {
                    conn.Open();

                    Cmd.CommandText = "update Customers set customer_name = '" + **I WANT TO GET THE UPDATED VALUE BUT FROM WHERE SHALL I GET IT?????** + "', modified_on = getdate(), modified_by = '" + System.Environment.UserName + "' where customer_id = '" + customerID + "'";
                    Cmd.CommandType = System.Data.CommandType.Text;
                    Cmd.Connection = conn;

                    Cmd.ExecuteNonQuery();
                    GridView1.DataBind();

                    // Close the Edit Mode
                    GridView1.EditIndex = -1;

                }
                catch (SqlException ee)
                {

                    ValidationError.Display(ee.Message);

                }

                finally
                {
                    Cmd.Dispose();
                    conn.Close();
                    conn.Dispose();

                }
            }

        }

    }

Any help would be greatly appreciated

  • 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-11T09:58:11+00:00Added an answer on June 11, 2026 at 9:58 am

    I think the code you’re looking for is:

    GridViewRow row = (GridViewRow)(((LinkButton)e.CommandSource).NamingContainer);
    string name = ((TextBox)row.FindControl("TextBox1")).Text
    
    Cmd.CommandText = "update Customers set customer_name = '" + name + "', modified_on = getdate(), modified_by = '" + System.Environment.UserName + "' where customer_id = '" + customerID + "'";
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a gridview control that has on onclick event bound to every cell.
I have a gridview that I want to read, delete, edit and update, I
I have a GridView webcontrol that has paging and sorting enabled. I've bound the
I have a GridView that has 3 columns: FirstName, LastName and a TemplateField FullName
I have web forms page that has 2 controls. A gridview and an associated
I have a GridView. My GridView has a column that is contains an Options
For example, Lets say that I have a gridview column which has important controls,
I have a user control that contains a GridView. The GridView has both a
I have a gridview that displays items details, I added two template fields one
I have an ASP.NET GridView that has four columns. The first three are typical

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.