I am using ASP and SQL Server.
Scenario: One of my tables in the database twice a foreign key is a specific table used.
The problem: When I want to display different data entered on these foreign keys by linq in ASP GridView, it displays the same data for different values.
Example: My first table that name "Table_1" with two data:
id2=Book, id4=Student
and i have second table with name "foreignKeys" too that has data like this:
Question: how can i use linq gridview to read different data name (Book and Student) from "foreignKeys"?
My Html code:
<asp:GridView ID="gvDeFrm" runat="server" AutoGenerateColumns="False" DataKeyNames="id" DataSourceID="linq">
<Columns>
<asp:BoundField DataField="Name" HeaderText="Book"></asp:BoundField>
<asp:BoundField DataField="Name" HeaderText="Student"></asp:BoundField>
</Columns>
</asp:GridView>
My behind code:
protected void linq_Selecting(object sender, LinqDataSourceSelectEventArgs e)
{
e.Result = (from f in db.foreignkey
select new
{
f.userId,
f.Table_1.Name
}
).ToList();
}
Thank you for your attention earlier.