|
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..
|
|
|
|
|
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 + ".";
}
}
<title>GridView Select Example
GridView Select Example
<asp:gridview id="CustomersGridView"
="" datasourceid="CustomersSource" autogeneratecolumns="False" autogenerateselectbutton="True" allowpaging="True" selectedindex="1" onselectedindexchanged="CustomersGridView_SelectedIndexChanged" onselectedindexchanging="CustomersGridView_SelectedIndexChanging" runat="server" datakeynames="CustomerID">
<columns>
<asp:boundfield datafield="CustomerID"
="" headertext="CustomerID" insertvisible="False" readonly="True" sortexpression="CustomerID">
<asp:boundfield datafield="FirstName"
="" headertext="FirstName" sortexpression="FirstName">
<asp:boundfield datafield="MiddleName"
="" headertext="MiddleName" sortexpression="MiddleName">
<asp:boundfield datafield="LastName"
="" headertext="LastName" sortexpression="LastName">
<asp:boundfield datafield="Phone"
="" headertext="Phone" sortexpression="Phone">
<selectedrowstyle backcolor="LightCyan"
="" forecolor="DarkBlue" font-bold="true">
<asp:label id="MessageLabel"
="" forecolor="Red" runat="server">
<asp:sqldatasource id="CustomersSource"
="" selectcommand="SELECT CustomerID, FirstName, MiddleName, LastName, Phone FROM SalesLT.Customer" connectionstring="<%$ ConnectionStrings:AdventureWorksLTConnectionString %>" runat="server">
|
|
|
|