![](/img/trans.png)
[英]Performance of conditional logic with gridview RowDataBound vs ItemTemplate/Regular databind
[英]Trouble with LINQ databind to GridView and RowDataBound
大家问候,
我正在使用VS 2008重新设计我的个人网站,并选择使用LINQ通过数据访问层创建。 我的网站的一部分将是一个小应用程序,可以帮助更好地管理我的预算。 我的第一个LINQ查询确实成功执行并显示在GridView
,但是当我尝试使用RowDataBound
事件处理结果并对其进行一些优化时,出现错误:
找不到类型或名称空间名称“
var
”(是否缺少using指令或程序集引用?)
这个有趣的部分是,如果我只是尝试输入var s = "s";
同一文件中的其他任何地方,我也遇到相同的错误。 如果我转到Web项目中的其他文件,则var s = "s";
编译良好。
这是LINQ查询调用:
public static IQueryable pubGetRecentTransactions(int param_accountid)
{
clsDataContext db;
db = new clsDataContext();
var query = from d in db.tblMoneyTransactions
join p in db.tblMoneyTransactions on d.iParentTransID equals p.iTransID into dp
from p in dp.DefaultIfEmpty()
where d.iAccountID == param_accountid
orderby d.dtTransDate descending, d.iTransID ascending
select new
{
d.iTransID,
d.dtTransDate,
sTransDesc = p != null ? p.sTransDesc : d.sTransDesc,
d.sTransMemo,
d.mTransAmt,
d.iCheckNum,
d.iParentTransID,
d.iReconciled,
d.bIsTransfer
};
return query;
}
protected void Page_Load(object sender, EventArgs e)
{
if (!this.IsPostBack)
{
this.prvLoadData();
}
}
internal void prvLoadData()
{
prvCtlGridTransactions.DataSource = clsMoneyTransactions.pubGetRecentTransactions(2);
prvCtlGridTransactions.DataBind();
}
protected void prvCtlGridTransactions_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
var datarow = e.Row.DataItem;
var s = "s";
e.Row.Cells[0].Text = datarow.dtTransDate.ToShortDateString();
e.Row.Cells[1].Text = datarow.sTransDesc;
e.Row.Cells[2].Text = datarow.mTransAmt.ToString("c");
e.Row.Cells[3].Text = datarow.iReconciled.ToString();
}//end if
}//end RowDataBound
到目前为止,我一直在使用Google搜索,但找不到很好的答案,因此我将其移交给了这个值得信赖的社区。 感谢您抽出宝贵时间为我提供帮助。
对我来说似乎很奇怪, var
是一个语言关键字,但是在这种情况下,编译器以某种方式将其视为类型。 由于您已经(成功地)在pubGetRecentTransactions()
)中使用了var
, pubGetRecentTransactions()
我假设您是针对.NET 3.5编译的,对吗?
VS有时会做非常奇怪的事情。 您是否尝试过重新启动VS,然后进行完全重建?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.