grid.Column("District_Id","District_Id"),
I have a webgrid column like that.but i need to display District name instead of district_Id
how to display that in my webgrid.please tell me how to do that.Its very urgent..
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Jignesh TrivediPosted May 21, 2014, 11:44 PM
Ok do one thing
Create one View Model
public class myData
{
public string DistrictName {get;set;}
public int DistrictId {get;set;}
public string Name {get;set;}
public String AccountNo {get;set;}
}
now in your action method. here I amassuming DistrictName is comes from DistrictMaster table
public ActionResult SHG()
{
var VersionRes = from vs in db.SHG_Master
join d in db.DistrictMaster on vs.vs.DistrictId equal d.DistrictId
select new myData {
DistrictId = vs.DistrictId,
DistrictName = d.DistrictName,
Name=vs.Name,
AccountNo=vs.AccountNo,
};
return view(versionRes.ToList());
}
}
create strongly type model with type Innumerable view model.
pass this view model to your web grid
hope this will help you.
Sasi ReddyPosted May 22, 2014, 1:39 AM
Sasi ReddyPosted May 21, 2014, 8:36 AM
Jignesh TrivediPosted May 21, 2014, 8:10 AM
Sasi ReddyPosted May 21, 2014, 8:04 AM
Jignesh TrivediPosted May 21, 2014, 7:26 AM
if yes there is chance to optimized it.
Sasi ReddyPosted May 21, 2014, 7:14 AM
Jignesh TrivediPosted May 21, 2014, 7:04 AM
hi,
As per my knowledge you cannot call user define sub function from the LINQ to entity query.
instead of doing this try following code
public ActionResult SHG()
{
var VersionResTest = from vs in db.SHG_Master
select new{
DistrictId = vs.DistrictId,
Name=vs.Name,
AccountNo=vs.AccountNo,
}
var VersionRes = from vs1 in VersionResTest
select new{
DistrictName=user.getDistrictName(vs1.DistrictId),
Name=vs1.Name,
AccountNo=vs1.AccountNo,
}
return view(versionRes.ToList());
}
hope this will help you.
Sasi ReddyPosted May 21, 2014, 6:58 AM
public ActionResult SHG()
{
var VersionRes = from vs in db.SHG_Master
DistrictName=user.getDistrictName(vs.DistrictId),
Name=vs.Name,
AccountNo=vs.AccountNo,
}
return view(versionRes.ToList());
}
I have a query like that.By using above query i can display in webgrid
but while calling that getDistrictName() it is giving error.
How to solve this?..
Jignesh TrivediPosted May 21, 2014, 6:22 AM
hi,
As per my knowledge, grid is used for the display purpose only It means whatever data you passed to grid will those data.
so if you want name display you query result must name column.
if you want to display unique data so same as query result must have unique data.
hope this will help you.
Sasi ReddyPosted May 21, 2014, 5:56 AM
Jignesh TrivediPosted May 21, 2014, 3:51 AM
hi,
here first argument is column header
this becomes
grid.Column("District Name","District_Id"),
hope this will help you.