我想在gridview中显示来自一个表的数据以及来自另一个表的关系计数 [英] I want to show data from one table and count of relation from another table in gridview

查看:68
本文介绍了我想在gridview中显示来自一个表的数据以及来自另一个表的关系计数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我正在一个网站上,我想显示两个表中的数据
例如CustomerOrder和CustomerDomain.
我想在gridview中显示数据.
我要显示的是客户订单明细"和客户域"计数.

HI All,

I am working on a website and I want to display data from two tables
eg CustomerOrder and CustomerDomain.
I want to display the data in gridview.
What i want to display is Customer order Details and Count of CustomerDomains.

try
{
    var query = from po in pc.CustomerDomainTbls
                join co in pc.CustomerOrderTbls
                on po.OrderID equals co.OrderID
                select new {co.OrderDate, co.CustomerTbl.CustomerName, co.EmployeeTbl.Name,co.ServiceTypeTbl.ServiceName, co.QuotedAmount, co.ExpectedCompletionDate };
    gridorders.DataSource = query;
    gridorders.DataBind();
}
catch (Exception rr)
{

}



谁能帮我在gridview中获取CustomerDomains的数量.

非常感谢您的快速回复

Kishor Kadam



Can any one help me to get the count of CustomerDomains in gridview.

Thank you very much for quick reply

Kishor Kadam

推荐答案

我认为这会对您有所帮助.

为RowCount编写函数:

I think that will help you.

Write the function for RowCount:

private int RowCount
{
    get { return Convert.ToInt32(ViewState["RowCount"]); }
    set { ViewState["RowCount"] = value; }
}



检索此:



Retrieve this:

using (MYDataClassesDataContext dc = new MYDataClassesDataContext())
{
    var rec = dc.CustomerDomainTbls.FirstOrDefault();
    if (rec == null)
    {
        Response.Write("");
    }
    else
    { 
        try
        {
            var query = from po in pc.CustomerDomainTbls
                join co in pc.CustomerOrderTbls
                on po.OrderID equals co.OrderID
                select new 
               {co.OrderDate, 
              co.CustomerTbl.CustomerName, 
                 co.EmployeeTbl.Name,
            co.ServiceTypeTbl.ServiceName, 
             co.QuotedAmount, co.ExpectedCompletionDate,
             
            Count = dc.po.Count()};
            gridorders.DataSource = query;
            gridorders.DataBind();
        }
        catch (Exception rr)
        {
        }
    }
}


这篇关于我想在gridview中显示来自一个表的数据以及来自另一个表的关系计数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆