views:

67

answers:

4

hi

I want to show data in my database with Linq in gridview but I can't do it.

this Code :

var o = (from i in MDB.Messages
             select new { Subject = i.Subject, Message_Code = i.ID_Message, Question_date = i.Date, Question_Name = i.aspnet_Membership.aspnet_User.UserName });

    EndInboxGrv.DataSource = o;

How do I solve this problem?

+1  A: 

Have you checked that the variable o has data?

Did you bind it - EndInboxGrv.DataBind(); after the setting of the DataSource?

klabranche
A: 

you want to bind the data to the gridview.Then only the datasource in the Gridview gets bind

e.g : EndInboxGrv.DataBind()

Read this one http://msdn.microsoft.com/en-us/library/ms178366.aspx

anishmarokey
A: 

Are you calling databind on the gridview? Unlike winforms you have to explicitly call DataBind() in asp.net. I didn't see it in your code above, so if DataBind() call is missing you'd see nothing.

var o = (from i in MDB.Messages
             select new { Subject = i.Subject, Message_Code = i.ID_Message, Question_date = i.Date, Question_Name = i.aspnet_Membership.aspnet_User.UserName });

    EndInboxGrv.DataSource = o;
    EndInboxGrv.DataBind();
Binz
+1  A: 

You should bind the grid

var o = (from i in MDB.Messages 
    select new {
  Subject = i.Subject,
  Message_Code = i.ID_Message,
  Question_date = i.Date,
  Question_Name = i.aspnet_Membership.aspnet_User.UserName 
    });
EndInboxGrv.DataSource = o;
EndInboxGrv.DataBind();
Yassir