RG-3
RG-3

Reputation: 6188

GridView not populating from LINQ statement

I have a GridView which is not bound to any DataSource. In my page load event I am writing this code:

 protected void Page_Load(object sender, EventArgs e)
    {
        string getEntity = Request.QueryString["EntityID"];
        int getIntEntity = Int16.Parse(getEntity);

        OISLinq2SqlVs1DataContext dt = new OISLinq2SqlVs1DataContext();
        var tr = from r in dt.Users
                 join s in dt.Entities on r.Entity_ID equals s.ID
                 where s.ID == getIntEntity
                 select new
                 {
                     s.Name,
                     r.FirstName,
                     r.LastName,
                     s.Email,
                     //r.Email,
                     r.UserID,
                     r.Pwd,
                     s.Company,
                     s.Description,
                     s.Phone,
                     s.Fax,
                     s.WebSite

                 };

        GridView1.DataSource = tr;
        GridView1.DataBind();

    }

the markup:

<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" 
     Height="348px" Width="656px">
</asp:GridView>

Now I can see the the value is coming from previous page, but my GridView is not populating anything. What I am doing wrong here? Please help! Thank you.

Upvotes: 0

Views: 396

Answers (2)

Oleks
Oleks

Reputation: 32343

You should set AutoGenerateColumns property to true which is required to have the data source define what columns appear.

Or you have to manually specify the columns to show.

Upvotes: 2

RG-3
RG-3

Reputation: 6188

<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" 
     Height="348px" Width="656px">
</asp:GridView>

Upvotes: 0

Related Questions