Anand N

Anand N

  • NA
  • 19
  • 31.4k

Bindin linq to the Gridview

Oct 10 2012 3:44 AM
Please help me to get out of this error....
I am getting error when i try to display more than one column in the griedview

protected void Button1_Click(object sender, EventArgs e)
    {
        //DataView dv = new DataView();
        try
        {
            Customer1[] obj = new Customer1[2];

            obj[0] = new Customer1(1, "anand", "belgaum");
            obj[1] = new Customer1(1, "vijay", "kerala");


            var query = from data in obj where data.Id == 1 select data;

           // var query = from data in obj where data.Id == 1 select data.Name;  This is working fine if i select only one column to display

            GridView1.DataSource = query;           // error
            GridView1.DataBind();
        }
        catch (Exception ex)
        {
            Response.Write(ex);

        }
    }



public class Customer1
{
    public int Id;
    public string Name;
    public string City;
    public Customer1(int id, string name, string city)
    {
        Id = id;
        Name = name;
        City = city;
    }

}

Answers (3)