C# getting GridView DataKeyNames values on OnRowDataBound

Last modified: July 01, 2021
<asp:GridView ID="GridViewMovie" OnRowDataBound="GridViewMovie_RowDataBound" DataKeyNames="Id" AutoGenerateColumns="False" runat="server"> <Columns> <asp:BoundField DataField="Name" HeaderText="Name" SortExpression="Name" /> <asp:BoundField DataField="Rating" HeaderText="Rating" SortExpression="Rating" /> </Columns> </asp:GridView>
protected void GridViewMovie_RowDataBound(object sender, GridViewRowEventArgs e) { if (e.Row.RowType == DataControlRowType.DataRow) { var id = GridViewMovie.DataKeys[e.Row.RowIndex].Value; } }