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.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Jignesh TrivediRank #16 · 50.3K reputationPosted May 21, 2014, 7:44 PM EDT
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.
Jignesh TrivediRank #16 · 50.3K reputationPosted May 20, 2014, 11:51 PM EDT
hi,
here first argument is column header
this becomes
grid.Column("District Name","District_Id"),
hope this will help you.
Sasi ReddyRank #4,458 · 342 reputationPosted May 21, 2014, 1:56 AM EDT
Jignesh TrivediRank #16 · 50.3K reputationPosted May 21, 2014, 2:22 AM EDT
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 ReddyRank #4,458 · 342 reputationPosted May 21, 2014, 2:58 AM EDT
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 TrivediRank #16 · 50.3K reputationPosted May 21, 2014, 3:04 AM EDT
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 ReddyRank #4,458 · 342 reputationPosted May 21, 2014, 3:14 AM EDT
Jignesh TrivediRank #16 · 50.3K reputationPosted May 21, 2014, 3:26 AM EDT
if yes there is chance to optimized it.
Sasi ReddyRank #4,458 · 342 reputationPosted May 21, 2014, 4:04 AM EDT
Jignesh TrivediRank #16 · 50.3K reputationPosted May 21, 2014, 4:10 AM EDT
Sasi ReddyRank #4,458 · 342 reputationPosted May 21, 2014, 4:36 AM EDT
Sasi ReddyRank #4,458 · 342 reputationPosted May 21, 2014, 9:39 PM EDT