我要綁定的GridView和我的自定義實體whitch我從數據庫 填充的實例,但我得到的錯誤不能設置爲一個實例 對象引用對象 我知道錯誤是從我gridlink 類時,選擇新的要設置爲鏈接財產 在這一行:link = { linkName = "tyr", linkSrc = "ytr" },
,因爲當我earase它的錯誤停止和GridView綁定 感謝C#LINQ選擇新類錯誤:未將對象引用設置到對象
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();
}
Stacktrace?.... –
可能重複[什麼是.NET中的NullReferenceException?](http://stackoverflow.com/questions/4660142/what-is-a-nullreferenceexception-in-net) –
什麼是是'pe.mandeh'和'pe.mant'的類型嗎? –