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.
You should set
AutoGenerateColumnsproperty totruewhich is required to have the data source define what columns appear.Or you have to manually specify the columns to show.