I have a detailsview where i set the datakey to be the primary key of the record it is displaying.
I am trying to access the value of the datakey as follows:
dim id as integer = Employer.DataKey("EmployerID") where Employer is the name of the FVand EmpID is the PK
When i do this i get an error saying the datakey does not have a value. I do not understand why. The only thing i can think of is that when the formview is created, there is nothing in the formview template that references the employerID.
The FV looks like this
<asp:FormView ID="Employer" runat="server" DataKeyNames="EmployerID" DataSourceID="ObjectDataSource1" DefaultMode="Edit">
<td colspan="3" height="30">
<asp:TextBox ID="CompanyName" runat="server" Text='<%# Bind("CompanyName") %>'></asp:TextBox>
...and so on
but there is nothing in the template that binds the employerID because I don't want this field displayed.
Do you know what is causing the FV to lose its datakey? How can i get it back?