前台,设置DataKeyNames:
<asp:GridView ID="dg" runat="server" AutoGenerateColumns="False" AllowPaging="True"
Width="100%" onrowdatabound="dg_RowDataBound" DataKeyNames ="EquipID,type">...
后台,获取数据:
protected void dg_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
if (e.Row.RowState == DataControlRowState.Normal || e.Row.RowState == DataControlRowState.Alternate)
{
GridView dg = e.Row.Parent.Parent as GridView;
string No = dg.DataKeys[e.Row.RowIndex].Values[0].ToString ();
string type = dg.DataKeys[e.Row.RowIndex].Values[1].ToString ();
}
}
}