none
Bind Datacontext table to Gridview RRS feed

  • Question

  • I understand that this is a solution using a predefined collection. But I was wondering how could I implement this solution using linq to sql with with a data context. Thanks

    GridView1.DataSource = Enumerable.Range(1, 5).Select(a => new
    {

    FirstName = String.Format("First Name {0}", a),
    LastName = String.Format"Last Name {0}", a),
    ShowButton = a.Equals(5)
    });
    GridView1.DataBind();

    Thursday, January 7, 2016 10:55 AM

Answers

  • Hi Ronald,

    >> But I was wondering how could I implement this solution using linq to sql with a data context.

    The following code snippet about using linq to sql with a data context for your reference.

    var query = from p in db.Products
       select new
          {
                id = p.ProductID,
                name = p.ProductName,
                ShowButton = p.ProductID.Equals(1)
          };
    GridView1.DataSource = query.ToList();
    GridView1.DataBind();

    Best regards,


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Friday, January 8, 2016 5:07 AM
    Moderator