Note that there are some explanatory texts on larger screens.

plurals
  1. POhow to get DatakeyValue from gridview being populated with linq
    text
    copied!<p>I have the following gridview:</p> <pre><code> &lt;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" &gt; &lt;AlternatingRowStyle CssClass="alternateItemStyle" /&gt; &lt;HeaderStyle CssClass="headerStyle" /&gt; &lt;PagerSettings Mode="NumericFirstLast" /&gt; &lt;RowStyle CssClass="itemStyle" /&gt; &lt;Columns&gt; &lt;asp:BoundField DataField="NOVID" HeaderText="NOVID" InsertVisible="false" ReadOnly="true" Visible="false"/&gt; &lt;asp:BoundField DataField="NOVNumber" HeaderText="NOV Number" SortExpression="NOVNumber" ItemStyle-HorizontalAlign="Center" /&gt; &lt;asp:BoundField DataField="NOVDate" HeaderText="NOV Date" SortExpression="NOVDate" ItemStyle-HorizontalAlign="Center" DataFormatString="{0:d}" /&gt; &lt;asp:BoundField DataField="CompanyName" HeaderText="Company Name" SortExpression="CompanyName" ItemStyle-HorizontalAlign="Center"&gt;&lt;/asp:BoundField&gt; &lt;asp:BoundField DataField="CargoTankID" HeaderText="Cargo Tank Number" SortExpression="CargoTankNumber" ItemStyle-HorizontalAlign="Center" /&gt; &lt;asp:BoundField DataField="ARBInspectorFirstName" HeaderText="InspectorFirstName" SortExpression="InspectorFirstName" ItemStyle-HorizontalAlign="Center" /&gt; &lt;asp:BoundField DataField="ARBInspectorLastName" HeaderText="InspectorLastName" SortExpression="InspectorLastName" ItemStyle-HorizontalAlign="Center" /&gt; &lt;asp:BoundField DataField="ViolationName" HeaderText="Violation Name" SortExpression="ViolationName" ItemStyle-HorizontalAlign="Center" /&gt; &lt;/Columns&gt; &lt;/asp:GridView&gt; </code></pre> <p>It is being populated on the page load event using linq:</p> <pre><code> 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(); </code></pre> <p>When I click on a row, I call this method:</p> <pre><code>protected void gvNOVs_OnSelectRow(object sender, GridViewCommandEventArgs e) { } </code></pre> <p>I'm not sure how to get the datakeyValue, I want to get the NOVID for the row that was clicked on. If I get e.CommandArgument.ToString(), it gives me the value for CargoTankID, I have no idea why it gives me that value.</p> <p>Anybody know how to get the NOVID for the row selected?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload