我有以下网格视图:
<asp:GridView ID="gvNOVs" runat="server" AllowPaging="true" AllowSorting="true" PageSize="10"
AutoGenerateColumns="false" Width="100%" BackColor="Transparent" GridLines="None"
RowStyle-HorizontalAlign="Left" PagerSettings-Mode="NumericFirstLast" DataKeyNames="NOVID"
OnRowDataBound="gvNOVs_RowDataBound"
OnRowCommand="gvNOVs_OnSelectRow"
OnPageIndexChanging="gvNOVs_PageIndexChanging"
OnSorting="gvNOVs_OnSorting"
>
<AlternatingRowStyle CssClass="alternateItemStyle" />
<HeaderStyle CssClass="headerStyle" />
<PagerSettings Mode="NumericFirstLast" />
<RowStyle CssClass="itemStyle" />
<Columns>
<asp:BoundField DataField="NOVID" HeaderText="NOVID" InsertVisible="false" ReadOnly="true" Visible="false"/>
<asp:BoundField DataField="NOVNumber" HeaderText="NOV Number" SortExpression="NOVNumber"
ItemStyle-HorizontalAlign="Center" />
<asp:BoundField DataField="NOVDate" HeaderText="NOV Date" SortExpression="NOVDate"
ItemStyle-HorizontalAlign="Center" DataFormatString="{0:d}" />
<asp:BoundField DataField="CompanyName" HeaderText="Company Name" SortExpression="CompanyName"
ItemStyle-HorizontalAlign="Center"></asp:BoundField>
<asp:BoundField DataField="CargoTankID" HeaderText="Cargo Tank Number" SortExpression="CargoTankNumber"
ItemStyle-HorizontalAlign="Center" />
<asp:BoundField DataField="ARBInspectorFirstName" HeaderText="InspectorFirstName"
SortExpression="InspectorFirstName" ItemStyle-HorizontalAlign="Center" />
<asp:BoundField DataField="ARBInspectorLastName" HeaderText="InspectorLastName" SortExpression="InspectorLastName"
ItemStyle-HorizontalAlign="Center" />
<asp:BoundField DataField="ViolationName" HeaderText="Violation Name" SortExpression="ViolationName"
ItemStyle-HorizontalAlign="Center" />
</Columns>
</asp:GridView>
它正在使用 linq 在页面加载事件中填充:
var NOVs = from n in db.CT_NOVs
join i in db.CT_Inspectors on n.ARBInspectorID equals i.CTInspectorID
join v in db.CT_ViolationTypes on n.ViolationTypeID equals v.ViolationTypeID
join t in db.CT_Tanks on n.CargoTankID equals t.CargoTankID
join c in db.CT_Companies on t.CompanyID equals c.CompanyID
orderby n.NOVNumber descending
select new
{
n.NOVID,
n.NOVNumber,
NOVDate = n.NOVDate.Value.ToShortDateString(),
ARBInspectorFirstName = i.FirstName,
ARBInspectorLastName = i.LastName,
v.ViolationName,
t.CargoTankID,
c.CompanyName
};
this.gvNOVs.DataSource = NOVs;
this.gvNOVs.DataBind();
当我点击一行时,我调用这个方法:
protected void gvNOVs_OnSelectRow(object sender, GridViewCommandEventArgs e)
{
}
我不确定如何获取 datakeyValue,我想获取单击的行的 NOVID。如果我得到 e.CommandArgument.ToString(),它给了我 CargoTankID 的值,我不知道为什么它给了我这个值。
有人知道如何获取所选行的 NOVID 吗?