Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. JavaScript
  4. How to find the row in the gridview that was selected

How to find the row in the gridview that was selected

Scheduled Pinned Locked Moved JavaScript
helpjavascriptdatabasetutorialcareer
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    MacIntyre
    wrote on last edited by
    #1

    I have a gridview of employee jobs. One job row gets selected and some items from the row and some items from the database populate a space below the Gridview on an aspx page. total hours is in the gridview row. The user enters the payrate into one of the fields on the aspx page. user enters another field for overtime rate. There is a DropdownList that has hourly and Hourly+. Stakeholder does not want the total hours displayed below the gridview. After the amounts are entered the operator selects from the dropdownlist. from a client side Javascript I need to find the row in the Gridview that was selected, get the total hours from the column of that row, then compute the total pay. The problem is I don't know how to locate the row that was selected from the Gridview. It is not the opject that is firing the current event. Can you help with a small snippet. Thanks..

    A 1 Reply Last reply
    0
    • M MacIntyre

      I have a gridview of employee jobs. One job row gets selected and some items from the row and some items from the database populate a space below the Gridview on an aspx page. total hours is in the gridview row. The user enters the payrate into one of the fields on the aspx page. user enters another field for overtime rate. There is a DropdownList that has hourly and Hourly+. Stakeholder does not want the total hours displayed below the gridview. After the amounts are entered the operator selects from the dropdownlist. from a client side Javascript I need to find the row in the Gridview that was selected, get the total hours from the column of that row, then compute the total pay. The problem is I don't know how to locate the row that was selected from the Gridview. It is not the opject that is firing the current event. Can you help with a small snippet. Thanks..

      A Offline
      A Offline
      Angel1320
      wrote on last edited by
      #2

      Try using this Example : <%@ Page language="C#" %> void CustomersGridView_SelectedIndexChanged(Object sender, EventArgs e) { // Get the currently selected row using the SelectedRow property. GridViewRow row = CustomersGridView.SelectedRow; // Display the company name from the selected row. // In this example, the third column (index 2) contains // the company name. MessageLabel.Text = "You selected " + row.Cells[2].Text + "."; } void CustomersGridView_SelectedIndexChanging(Object sender, GridViewSelectEventArgs e) { // Get the currently selected row. Because the SelectedIndexChanging event // occurs before the select operation in the GridView control, the // SelectedRow property cannot be used. Instead, use the Rows collection // and the NewSelectedIndex property of the e argument passed to this // event handler. GridViewRow row = CustomersGridView.Rows[e.NewSelectedIndex]; // You can cancel the select operation by using the Cancel // property. For this example, if the user selects a customer with // the ID "ANATR", the select operation is canceled and an error message // is displayed. if (row.Cells[1].Text == "ANATR") { e.Cancel = true; MessageLabel.Text = "You cannot select " + row.Cells[2].Text + "."; } } GridView Select Example

      GridView Select Example

      <

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups