1

Linq result data binding- How to change the column header?. Grid enabled with pagination and sorting. I am trying to change the column names with spaces for e.g. Companyname = Company Name. How to so this?

var finalResult = AllCompany.Select(i => new
{
    noteLink = i.ID.ToString(),                         //1
    editLink = i.ID.ToString(),                         //2
    CompanyName = i.Fields["Company Name"].ToString(),  //3
    Address1 = i.Fields["Address Line 1"].ToString(),   //4
})
.Distinct()
.OrderByDescending(i => i.CompanyName)
.ToArray();

GvResults.DataSource = finalResult.ToList();
GvResults.DataBind();

1 Answers1

1

To do that, you might want to declare a POCO:

public class CompanySearchResult {
    [Browsable(false)]
    public string noteLink {get;set;}
    [Browsable(false)]
    public string editLink {get;set;}
    [DisplayName("Company Name")]
    public string CompanyName {get;set;}
    [DisplayName("Address Line 1")]
    public string Address1 {get;set;}
}

and do:

var finalResult = AllCompany.Select(i => new CompanySearchResult
{
    noteLink = i.ID.ToString(),                         //1
    editLink = i.ID.ToString(),                         //2
    CompanyName = i.Fields["Company Name"].ToString(),  //3
    Address1 = i.Fields["Address Line 1"].ToString(),   //4
})
// etc
Marc Gravell
  • 1,026,079
  • 266
  • 2,566
  • 2,900