Click here to Skip to main content
15,885,216 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello

It is such that I must had both user information and comment content forward, but right now it will only remove the user name appears on the page.

What am I doing wrong here?

var UsersKommentar = from KommentarA in db.forumkommentars
                             join BrugereA in db.brugeres on KommentarA.brugerid equals BrugereA.Id
                             where KommentarA.Id == getid
                             orderby KommentarA.Id descending
                             select BrugereA;

        RepeaterKommentar.DataSource = UsersKommentar;
        RepeaterKommentar.DataBind();


EIDT Updater

var UsersKommentar = from KommentarA in db.forumkommentars
                             join BrugereA in db.brugeres on KommentarA.brugerid equals BrugereA.Id
                             where KommentarA.Id == getid
                             orderby KommentarA.Id descending
                             select new
                             {
                                 UserName = BrugereA.fornavn + " " + BrugereA.efternavn
                             };

        RepeaterKommentar.DataSource = UsersKommentar;
        RepeaterKommentar.DataBind();


<asp:Repeater ID="RepeaterKommentar" runat="server">
                    <ItemTemplate>
                        <div class="kommentarBox">
                            <%--print content here--%>
                        </div>
                    </ItemTemplate>
                </asp:Repeater>
Posted
Updated 24-Apr-15 9:03am
v2

1 solution

If I understand correctly, this should be what you want:
C#
var usersKommentar = from KommentarA in db.forumkommentars
                     join BrugereA in db.brugeres on KommentarA.brugerid equals BrugereA.Id
                     where KommentarA.Id == getid
                     orderby KommentarA.Id descending
                     select new { // change/add property names below as required:
                                  UserName = BrugereA.UserName,
                                  OtherUserInfo = BrugereA.Something,
                                  Kommentar = KommentarA.Kommentar,
                                  Date = KommentarA.Date
                                };
 
RepeaterKommentar.DataSource = usersKommentar;
RepeaterKommentar.DataBind();

We're returning an anonymous (compiler generated) type here in order to get columns from both Users and Comments. As I don't know how your columns/properties are named, I just wrote some examples there. Please change and add as you need it.

One thing looks to me like it's probably an oversight from you: You're ordering by KommentarA.Id and also filtering by KommentarA.Id. One of those lines doesn't make much sense or maybe you intended to use some other column for filtering or ordering.

Edit after comments:

An alternative way, if you don't get the above to work with the Repeater:
C#
class UserKommentar
{
    // change/add properties as required:
    public string UserName { get; private set; }
    public string Kommentar { get; private set; }

    public UserKommentar(string userName, string kommentar)
    {
        UserName = userName;
        Kommentar = kommentar;
    }
}

// and then:

var usersKommentar = from KommentarA in db.forumkommentars
                     join BrugereA in db.brugeres on KommentarA.brugerid equals BrugereA.Id
                     where KommentarA.Id == getid
                     orderby KommentarA.Id descending
                     select new UserKommentar(BrugereA.UserName, KommentarA.Kommentar);
 
RepeaterKommentar.DataSource = usersKommentar;
RepeaterKommentar.DataBind();
 
Share this answer
 
v2
Comments
Jesper Petersen 24-Apr-15 14:00pm    
So that means that the content that I need out I write just for new { and then in here };
Sascha Lefèvre 24-Apr-15 14:10pm    
exactly
Jesper Petersen 24-Apr-15 14:20pm    
How should I provide exactly that on the page ??
Sascha Lefèvre 24-Apr-15 14:21pm    
Please clarify ?
Jesper Petersen 24-Apr-15 14:23pm    
I mean, if I write like this? <%# Eval("UserName") %>, However, it will not work at all.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900