Trouble with LINQ databind to GridView and RowDataBound
Posted
by Michael
on Stack Overflow
See other posts from Stack Overflow
or by Michael
Published on 2010-02-06T12:29:33Z
Indexed on
2010/06/12
5:02 UTC
Read the original article
Hit count: 390
Greetings all,
I am working on redesigning my personal Web site using VS 2008 and have chosen to use LINQ to create by data-access layer. Part of my site will be a little app to help manage my budget better. My first LINQ query does successfully execute and display in a GridView
, but when I try to use a RowDataBound
event to work with the results and refine them a bit, I get the error:
The type or namespace name '
var
' could not be found (are you missing a using directive or an assembly reference?)
This interesting part is, if I just try to put in a var s = "s";
anywhere else in the same file, I get the same error too. If I go to other files in the web project, var s = "s";
compiles fine.
Here is the LINQ Query call:
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
My googling to date hasn't found a good answer, so I turn it over to this trusted community. I appreciate your time in assisting me.
© Stack Overflow or respective owner