gridview如何获取选中行的上一行数据
发布网友
发布时间:2022-04-24 19:12
我来回答
共2个回答
热心网友
时间:2022-04-24 20:42
前台代码:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default2.aspx.cs" Inherits="Default2" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>无标题页</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:GridView ID="GridView1" runat="server" OnSelectedIndexChanging="GridView1_SelectedIndexChanging">
<Columns>
<asp:BoundField HeaderText="id" DataField="id" />
<asp:CommandField ButtonType="button" ShowSelectButton="true" />
</Columns>
</asp:GridView>
</div>
</form>
</body>
</html>
后台代码:
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
public partial class Default2 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void GridView1_SelectedIndexChanging(object sender, GridViewSelectEventArgs e)
{
GridView1.Rows[e.NewSelectedIndex].Cells[0].text;//此为你要得到的选中行的第一列的数据
GridView1.Rows[e.NewSelectedIndex-1].Cells[0].text;//此为你要得到的选中行的上一行的第一列的数据
}
}
希望对你有些帮助
热心网友
时间:2022-04-24 22:00
RowCommand 事件的 参数 e里可以获取 RowIndex
还可以获取RowType
其他不多说了