Please i a problem trying to get the primary key of a gridview control bounded by an entitydata source.I have a table called staff and this table has about 25 columns on it.The primary key of this table consist of a combination of two columns which is column [StaffID] and column [SchoolID].
I used the entitydatasource control to hook up to the table.I did not select all the columns i just selected four of the columns.Below is the markup of the entitydatasource control.
<asp:EntityDataSource ID="EntityDataSource1" runat="server"
ContextTypeName="DEMOWEBAPPLICATION.PriSecDbEntities" EnableFlattening="False"
AutoGenerateOrderByClause="true"
EntitySetName="Staffs" EntityTypeFilter="Staff"
Select="it.[StaffID], it.[SchoolID], it.[Surname], it.[FirstName]">
<OrderByParameters>
<asp:Parameter
DefaultValue="StaffID" />
</OrderByParameters>
</asp:EntityDataSource>
I bounded this to a gridview control.My question is i want a situation when i click on a row on the gridview i will be able to show the different columns from my staff table on different textbox control(for example i will be able to do something like this txtSurname.text=newStaff.name and so on) and i will be able to edit and updated it and it will updates on the database. I have been trying to create an object of staff and get the primary key column by doing this
Dim newStaff As Staff = DirectCast(grdLoadStaffDetails.SelectedPersistedDataKey("StaffID"), Staff)
This is how i normally do it when using a datagrid with windows form application.
Dim selectedUser = DirectCast(Me.grdLoadStaffDetails.CurrentRow.DataBoundItem, Staff)
I want the equivalent of this with a gridview control
in the gridview selectedindexchanged event handler but it throws up an invalid cast execption hour. I have been pulling out my hair out for the past five hours. Any help is highly appreciated. Thanks