Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4625260
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T03:14:48+00:00 2026-05-22T03:14:48+00:00

I’m trying to use LINQ to bind the data in my GridView. In my

  • 0

I’m trying to use LINQ to bind the data in my GridView.

In my Service.cs file I have a method for fetching the entries for a specific logged in user:

public List<tidsregistrering> ShowTidregistreringer()
{
    var CurrentMedarbejder = FindUser(HttpContext.Current.Session["email"].ToString());

    var tempList = (from t in kdc.tidsregistrerings
                    join p in kdc.projekts on t.projektid equals p.id
                    join k in kdc.kundes on t.kundeid equals k.id
                    join o in kdc.øvriges on t.øvrigeid equals o.id
                    where t.medarbejderid == CurrentMedarbejder.id
                    select t).ToList();    

    return tempList;
}

Where the kdc is my DataContext. I have tried joining the different tables together, but no data is shown in my GridView. If I leave out the joins, I get data… In my other tables I have a column called navn (name). I want that name printet in my GridView instead of the foreign key reference…

My GridView:

<asp:GridView ID="GridView1" runat="server">
    <Columns>
        <asp:BoundField DataField="tidsforbrug" HeaderText="Tidsforbrug" />
        <asp:BoundField DataField="dato" HeaderText="Dato" />
        <asp:BoundField DataField="<%# Bind("projekt.id") %>" HeaderText="Projekt" />
        <asp:BoundField DataField="<%# Bind("kunde.id") %>" HeaderText="Kunde" />
        <asp:BoundField DataField="<%# Bind("øvrige.id") %>" HeaderText="Øvrigt" />
        <asp:BoundField DataField="done" HeaderText="Done" />
    </Columns>
</asp:GridView

My binding happens at Page_load:

GridView1.DataSource = service.ShowTidregistreringer();
GridView1.DataBind();

How do I do this?

Edit:
And for good measure this is my list, as of now… And I want those numbers in projektid, kundeid and øvrigeid to be joined with my foreign key tables.

*Edit2:**
For even better measure this is how my database tables are created:

CREATE TABLE chef(
    id int identity primary key,
    email varchar(100) unique not null,
    password char(100) not null,
    navn varchar(100) not null
);

CREATE TABLE medarbejder(
    id int identity primary key,
    email varchar(100) unique not null,
    password char(100) not null,
    navn varchar(100) not null,
    chefid int foreign key references chef(id)
);

CREATE TABLE projekt(
    id int identity primary key,
    navn varchar(50) not null,
    beskrivelse varchar(255) not null
);

CREATE TABLE kunde(
    id int identity primary key,
    navn varchar(50) not null,
    beskrivelse varchar(255) not null
);

CREATE TABLE øvrige(
    id int identity primary key,
    navn varchar(50) not null,
);

CREATE TABLE tidsregistrering(
    id int identity primary key,
    tidsforbrug float,
    dato datetime,
    projektid int foreign key references projekt(id),
    kundeid int foreign key references kunde(id),
    øvrigeid int foreign key references øvrige(id),
    medarbejderid int foreign key references  medarbejder(id) not null,
    done bit
);

Edit3:
I have remade my LINQ-query to this:

List<tidsregistrering> tempList = (from t in kdc.tidsregistrerings
                                   join p in kdc.projekts on t.projektid equals p.id into p_t
                                   join k in kdc.kundes on t.kundeid equals k.id into k_t
                                   join o in kdc.øvriges on t.øvrigeid equals o.id into o_t
                                   from k in k_t.DefaultIfEmpty()
                                   from p in p_t.DefaultIfEmpty()
                                   from o in o_t.DefaultIfEmpty()
                                   where t.medarbejderid == CurrentMedarbejder.id
                                   select t).ToList();

But it still doesn’t select what’s joined…

https://i.stack.imgur.com/eSFQX.png

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T03:14:48+00:00Added an answer on May 22, 2026 at 3:14 am

    Run this query in SQL Server Management studio

    select t.* from tidsregistrerings t 
    inner join projekts p on t.projektid = p.id
    inner join kundes k on t.kundeid    = k.id 
    inner join øvriges o on t.øvrigeid = o.id 
    where t.medarbejderid = [whatever CurrentMedarbejder id is]
    

    Then comment out the joins one at a time, until you get your results returned. This will show you which table is preventing your data from being returned.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to understand how to use SyndicationItem to display feed which is
I have just tried to save a simple *.rtf file with some websites and
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I am trying to render a haml file in a javascript response like so:
I want use html5's new tag to play a wav file (currently only supported
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I'm trying to use string.replace('’','') to replace the dreaded weird single-quote character: ’ (aka
I have a reasonable size flat file database of text documents mostly saved in
I am trying to loop through a bunch of documents I have to put
I have some data like this: 1 2 3 4 5 9 2 6

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.