动态地将数据值绑定到转发器中

时间:2016-02-16 09:54:02

标签: c# linq

我尝试将数据值绑定到转发器,并使用银行名称和每个银行的余额。余额计算为balance = sum(debit) - sum(credit),我试图得到如下结果:

-------------------
bank name | amount|
------------------|
   a      | 1200  |
------------------|
   b      | 1500  |
------------------|
   c      | 2400  |
-------------------

为此我使用了代码:

protected void bank_account()
{
    var balance = 0;
    using (var context = new sem_dbEntities())
    {

        var query = (from b in context.banks
                     join h in context.heads on b.h_id equals h.h_id
                     where b.bankstatus != 3 && (h.pid == 13 || h.h_id == 9)
                     select new { b.acc_name, b.h_id }).Take(4);
        foreach (var item in query)
        {
            var debit1 = (from p in context.ledgers where p.h_id == item.h_id select p.debit).Sum();
            var credit1 = (from q in context.ledgers where q.h_id == item.h_id select q.credit).Sum();
            balance = Convert.ToInt32( debit1 - credit1);
            var query1 = (from b in context.banks
                          join h in context.heads on b.h_id equals h.h_id
                          where b.bankstatus != 3 && (h.pid == 13 || h.h_id == 9)
                          select new { b.acc_name, b.h_id, balance }).Take(1);
            foreach (var item1 in query1)
            {
                Repeater1.DataSource = query1.ToList();
                Repeater1.DataBind();
            }
        }
    }
}

0 个答案:

没有答案