Creating custom linq column names in a list
We return the general list to the GridView, which then automatically generates the columns to display the report:
//Generate List
List<Stock> allStock = blStock_Collection.getAll();
//export custom view for report datagrid
return (from myStock in allStock
select new
{
myStock.Category,
myStock.Description,
myLowStock.UnitPrice,
myLowStock.CurrentQuantity
});
Our client has requested that we provide multilingual support on our site (in English and Polish), in particular the column headings on the grids. Therefore, we need to get rid of the automatic generation option in all of our data networks and add translations for each column manually.
I was wondering if there is a way to do this by creating a data source that will save us a lot of time, for example. changing this line:
myStock.Category,
to something like:
languagePack.Category = myStock.Category,
This of course throws the "Invalid anonymous type member declarator" error. Any advice?
source to share
Maybe I misunderstood something, but if you just want to insert your language into it (LanguagePack is just a class containing your values):
class LanguagePack
{
public int Category { get; set; }
public string Description { get; set; }
public decimal UnitPrice { get; set; }
public int CurrentQuantity { get; set; }
public int LanguageName { get; set; }
}
return (from myStock in allStock
select new LanguagePack
{
Category = myStock.Category,
Description = myStock.Description,
UnitPrice = myLowStock.UnitPrice,
CurrentQuantity = myLowStock.CurrentQuantity,
LanguageName = "Polish" // or english or whatever... maybe LanguageId or something corresponding to your model
});
source to share