i want to bind gridview with my custom entity whitch i populate from data base but i get error Object reference not set to an instance of an object i know the error is from my gridlink class when select new and want to set to link property in this行:link = { linkName = "tyr", linkSrc = "ytr" },
因为当我删除它时,错误停止和gridview绑定谢谢
public class gridcolumns
{
public decimal cost { get; set; }
public Int32 count { get; set; }
public gridlink link { get; set; }
public gridcolumns()
{
// TODO: Complete member initialization
}
}
public class gridlink
{
public string linkName { get; set; }
public string linkSrc { get; set; }
public gridlink()
{
}
}
protected void Page_Load(object sender, EventArgs e)
{
Data281DataContextDataContext conx = new Data281DataContextDataContext();
List<tbl_2_CheckReqNo_NotValid> allresult = conx.tbl_2_CheckReqNo_NotValids.ToList();
gridcolumns lastMantWithDate = new gridcolumns();
if (Request.QueryString.Count == 0)
{
var lastMantWithDaste = from pe in allresult //where allresult != null
orderby Convert.ToDecimal(pe.mandeh) descending
group pe by pe.mant into grouped
where grouped != null
select new gridcolumns
{
link = { linkName = "tyr", linkSrc = "ytr" },
cost = grouped.Sum(g => Convert.ToDecimal(g.mandeh)),
count = grouped.Count(),
};
GrdOstan.DataSource = lastMantWithDaste;
GrdOstan.DataBind();
}