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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T04:37:29+00:00 2026-05-21T04:37:29+00:00

I have a GridView and I am updating it through LINQ through C#. I

  • 0

I have a GridView and I am updating it through LINQ through C#. I want to access the elements in my GridView and store them in the variable. Then I will pass these variables into my LINQ query.

How should I access the items in my GridView? Here is my code:

protected void gvShowComm_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
    string productID = gvShowComm.DataKeys[e.RowIndex]["Product_ID"].ToString(); //Working!
    string planName = gvShowComm.DataKeys[e.RowIndex]["PlanName"].ToString(); //Working!
    string hiComm = gvShowComm.DataKeys[e.RowIndex]["HiCommissionOld"].ToString(); //Working!
    string lowComm = gvShowComm.DataKeys[e.RowIndex]["LowCommissionOld"].ToString(); //Working!

    gvShowComm.DataBind();
}

Markup:

<asp:GridView runat="server" Height="233px" Width="602px" ID ="gvShowComm" 
    CellPadding="4" ForeColor="#333333" GridLines="None" OnRowEditing = "gvShowComm_RowEditing" 
    OnRowUpdating = "gvShowComm_RowUpdating" 
    OnRowCancelingEdit = "gvShowComm_RowCancelingEdit" DataKeyNames = "Product_ID, PlanName, HiCommissionOld, LowCommissionOld">       
    <Columns>
        <asp:CommandField ShowCancelButton="True" ShowEditButton="True" />
    </Columns>
</asp:GridView>
  • 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-21T04:37:29+00:00Added an answer on May 21, 2026 at 4:37 am

    The GridViewUpdateEventArgs has properties on it that allow you to get at the Keys, OldValues, and NewValues collections for a particular row.

    You could access it like so:

    protected void gvShowComm_RowUpdating(object sender, GridViewUpdateEventArgs e)
    {
        //Product_ID is a column that I am displaying in my GV!
        int Product_ID = Int32.Parse(e.Keys["Product_ID"]);
    
        Entity_Product_Point ev = new Entity_Product_Point();
    
        ev.MyDateTime = DateTime.Parse(e.NewValues["MyProp"]);
    
        // And so on...
    }
    

    But this sucks pretty hard! ASP.Net can do the work for you, using one of the DataSource classes available. For your purposes you should look into the LinqDataSource

    It is worth noting that while the DataSource classes can be useful and nice, they have quite a bit of magic going on, and you can pretty much throw out the possibility of using any testable patterns with them. (see WebFormsMVP)

    If that isn’t a concern, then go for it. But achieving clean separation of concerns is better in the long run. In that case you would need to implement a facade wrapper around your business logic and use the ObjectDataSource.

    Either way you are better off than manually rooting around in key/value pair collections looking for values and then converting them back to their proper types.

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

Sidebar

Related Questions

Have a gridview control which will show X amount of rows. I want to
I have a GridView what I fill through a LINQ expression. Something like this:
I have GridView with connected SqlDataSource and I want cancel updating row when my
I have a Gridview and I try to Iterate through the NewValues collection and
I want to conditionally call update statement on sqldatasource. I have a gridview and
I have gridview with ajax rating control where i am updating rating value on
I have a Gridview with these parameters: <asp:GridView runat=server ID=ItemGrid CssClass=Grid AutoGenerateColumns=false AutoGenerateDeleteButton=true OnRowDeleting=RowDeleting
I have GridView and I want to be able to switch between adapters. Context:
I have Gridview and I want to retrieve some Information from data base(SQL). and
I have a GridView which I am populating by calling a method to return

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.