Hi ahsan.ali,
I have checked your code. Its working correctly. Refer the below sample.
HTML
<asp:GridView runat="server" ID="gridControl" />
C#
protected void Page_Load(object sender, EventArgs e)
{
using (NorthwindEntities dc = new NorthwindEntities())
{
var q = dc.Customers.Select(c => new { c.CustomerID, c.ContactName, c.Country, c.City, c.Address }).Take(20);
var result = q.AsEnumerable().Select((x, RowNumber) => new
{
RowNumber = RowNumber + 1,
ID = x.CustomerID,
Name = x.ContactName,
Category = x.Country,
Price = x.City,
ItemDiscription = x.Address
});
gridControl.DataSource = result.ToList();
gridControl.DataBind();
gridControl.Caption = "<b>RECORDS : </b>" + result.Count();
}
}
VB.Net
Protected Sub Page_Load(sender As Object, e As EventArgs) Handles Me.Load
Using dc As New NorthwindEntities()
Dim q = dc.Customers.[Select](Function(c) New With {c.CustomerID, c.ContactName, c.Country, c.City, c.Address}).Take(20)
Dim result = q.AsEnumerable().[Select](Function(x, RowNumber) New With { _
Key .RowNumber = RowNumber + 1, _
Key .ID = x.CustomerID, _
Key .Name = x.ContactName, _
Key .Category = x.Country, _
Key .Price = x.City, _
Key .ItemDiscription = x.Address _
})
gridControl.DataSource = result.ToList()
gridControl.DataBind()
gridControl.Caption = "<b>RECORDS : </b>" + result.Count().ToString()
End Using
End Sub
Screenshot
