当前位置:编程学习 > C#/ASP.NET >>

页面绑定问题,求大虾帮助

页面上需要得到一个某客户某月份发货清单。统计列表得应该得到如下格式结果:

              产品名1    产品名2   产品名3   产品名4

2011/3/1        10         0          0        0 
2011/3/2        0          10         0        0
20113/3         0          50        30       20
数量合计        10         60        30       20
单价(元)      2         3          4         5
合计           20        180         120      100

本月销售合计         420元


现在发货表里有字段: ID,产品ID,产品名称,发货数量,发货单价,发货价格(单价*数量得出),发送时间,客户ID号。
 客户订购产品表里字段:产品ID,产品名称,客户ID,单价。

请问我在页面要如何绑定才能得到上面这样的表格??? 我用了嵌套,但是页面非常的乱,得不这样的效果
    <table class="data_table2" width="100%" cellspacing="0" cellpadding="0">
                    <tr>
                        <td colspan="3" class="td_s2">
                            <span style="font-size: 24pt">结算清单</span></td>
                    </tr>
                    <tr>
                        <td style="width: 340px">
                            <span style="font-size: 14pt">送洗单位:<asp:Label ID="Label2" runat="server" Font-Bold="True"
                                Text="Label"></asp:Label></span>
                        </td>
                        <td colspan="2">
                            <span style="font-size: 14pt">结算月份:<asp:Label ID="Label3" runat="server" Font-Bold="True"
                                Text="Label"></asp:Label></span></td>
                    </tr>
                    <tr>
                        <td class="td_bg" colspan="4">
                            <table width="100%" border="0" cellspacing="0" cellpadding="0">
                              <asp:Repeater ID ="rpt" runat="server" onitemdatabound="rpt_ItemDataBound" >
                                 <ItemTemplate> 
                                <tr>
                                        <td align="center">
                                        时间</td>
   
                                        <td align="center">
                                        <%#DataBinder.Eval(Container.DataItem,"ProductName")%></td>
  
                                </tr> 
                                <asp:Repeater ID ="rp2" runat="server">
                                 <ItemTemplate>
                                        <tr>
                                            <td align="center">
                                                <%# DataBinder.Eval(Container.DataItem, "SendTime", "{0:d}")%>
                                            </td>
                                            <td align="center">
                                               <%# DataBinder.Eval(Container.DataItem, "SumPrice")%>
                                                 
                                            </td>
                                     </ItemTemplate>
                                   </asp:Repeater>
                                 </ItemTemplate>
                                   </asp:Repeater>
                            </table>
                        </td>
                    </tr>
                 
                </table>


后台:
 protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            if (oUiPage.RequestID > 0)
           {
            int iClinentID=Convert.ToInt32( Request.QueryString["ID"].ToString());
            string idatetime = Request.QueryString["Date"].ToString();
            //显示数据
            int RecordCount = 0;
            ArrayList myArray = new ArrayList();
            myArray.Add(iClinentID);
            if (Pages == 0)//没搜索的时候

             this.rpt.DataSource = new OA_SendProductsBLL().GetClientProductName(Pages, myArray, PageSize, out RecordCount);
            this.rpt.DataBind();
            }
        }

    }
    protected void rpt_ItemDataBound(object sender, RepeaterItemEventArgs e)
    {
        if(e.Item.ItemType==ListItemType.Item || e.Item.ItemType ==ListItemType.AlternatingItem)
        {
            Repeater rep2 = e.Item.FindControl("rp2") as Repeater;
            //找到分类Repeater关联的数据项 
            DataRowView rowv =(DataRowView)e.Item.DataItem;
            //提取分类ID 
            int iProductID = Convert.ToInt32(rowv["ProductID"]);
            //里面的Repeater
            ArrayList myArray = new ArrayList();
            DateTime Dt = DateTime.Parse(Request.QueryString["Date"]);
            int iClinentID = Convert.ToInt32(Request.QueryString["ID"].ToString());
            myArray.Add(iProductID);
            myArray.Add(iClinentID);
            myArray.Add(Dt.Month);
            myArray.Add(Dt.Year);
            rep2.DataSource = new OA_SendProductsBLL().GetClientProductSumPrice(Pages, myArray, PageSize, out RecordCount);
            rep2.DataBind();

        }

    }

函数 
        /// <summary>
        /// 作用:得到客户订购的产品名称
        /// </summary>
        /// <param name="nCurrentPage"></param>
        /// <param name="sWhere"></param>
        /// <param name="nRecordCount"></param>
        /// <returns></returns>
        public DataTable GetClientProductName(int nCurrentPage, ArrayList sWhere, int nPageSize, out int nRecordCount)
        {

            PagingLargeDM model = new PagingLargeDM();

            string sTemp = string.Empty;
            model.TableNames = "OA_ContractProduct inner join OA_Contract on OA_ContractProduct.ContractID=OA_Contract.ContractID";
            model.CurrentPage = nCurrentPage;
            model.PrimaryKey = "OA_ContractProduct.ContractProductID";
            model.PageSize = nPageSize;
            model.Order = "OA_ContractProduct.ContractProductID DESC ";
            model.Fields = "OA_ContractProduct.ProductID,OA_ContractProduct.ProductName,OA_ContractProduct.ContractID,OA_ContractProduct.LanguageID,OA_ContractProduct.Price,OA_ContractProduct.ServerMonth,OA_ContractProduct.SumPrice,OA_ContractProduct.TiChengUserID,OA_ContractProduct.TiChengDian,OA_ContractProduct.TiChengName,OA_Contract.SafeClientID";

            sTemp = "OA_Contract.SafeClientID ='"+sWhere[0].ToString()+"'";

            model.Filter = sTemp;

            return oPagingLargeDB.GetAllByWhere(model, out  nRecordCount);

        }

   /// <summary>
        /// 作用:得到客户订购的产品名称数量,价格
        /// </summary>
        /// <param name="nCurrentPage"></param>
        /// <param name="sWhere"></param>
        /// <param name="nRecordCount"></param>
        /// <returns></returns>
        public DataTable GetClientProductSumPrice(int nCurrentPage, ArrayList sWhere, int nPageSize, out int nRecordCount)
        {

            PagingLargeDM model = new PagingLargeDM();

            string sTemp = string.Empty;
            model.TableNames = "OA_SendProducts";
            model.CurrentPage = nCurrentPage;
            model.PrimaryKey = "ContractProductID";
            model.PageSize = nPageSize;
            model.Order = "SendTime DESC ";
            model.Fields = "isnull(sum(Convert(int,Nummber)),0)as Sumprice,SendTime";
            model.Group = "SendTime";

            sTemp = "ProductID ='" + sWhere[0].ToString() + "' and SaleClientID = '" + sWhere[1].ToString() + "' and  month(SendTime)='" + sWhere[2].ToString() + "' and  year(sendtime) ='" + sWhere[3].ToString() + "' ";

            model.Filter = sTemp;

            return oPagingLargeDB.GetAllByWhere(model, out  nRecordCount);

        }


--------------------编程问答-------------------- 后台把数据构造好,用GridView、Repeater显示 --------------------编程问答-------------------- 数量合计 10 60 30 20
单价(元) 2 3 4 5
合计 20 180 120 100

这些可以显示在Footer里 --------------------编程问答--------------------
引用 1 楼 ihandler 的回复:
后台把数据构造好,用GridView、Repeater显示


这个页面是需要根据客户ID和时间来构造的,所以每个客户订购的产品都不一样,也就是说客户1订购了5个产品,那么这个页面就是显示5列,客户2订购了1个产品,那么就是显示1列,这个只显示他们订购了的产品,后台数据不好构造啊。 我现在用Repeater嵌套能得出数据,就是页面乱的 。。。 --------------------编程问答--------------------
引用 2 楼 ihandler 的回复:
数量合计 10 60 30 20
单价(元) 2 3 4 5
合计 20 180 120 100

这些可以显示在Footer里


求教详细,谢谢。 --------------------编程问答-------------------- 所以我在做的时候就把横排产品名Repeater出来,然后把ProductID作为下面发货数量的查询条件。难道我的做法不对ma ? --------------------编程问答-------------------- 每列显示一个产品? SQL 行转列呢? --------------------编程问答-------------------- 也可以用DataList试试 --------------------编程问答-------------------- 产品为什么要以列的形式显示呢?如果有很多产品那页面不好看呀。我们在做的时候产品都是以行的形式展示的,那样方便查看的呀。如下:

产品名称  时间      单价      数量   金额
产品1    2011-3-1    20       10     200
产品2    2011-3-2    20       20     400

合计:                        30     600

查询条件可以按产品和时间来查询,可以给定一个时间段,然后根据 产品名称 ,单价,数量,金额分组查询,那样不是很直观。这时不查询时间 --------------------编程问答--------------------
引用 8 楼 shmily_zll 的回复:
产品为什么要以列的形式显示呢?如果有很多产品那页面不好看呀。我们在做的时候产品都是以行的形式展示的,那样方便查看的呀。如下:

产品名称 时间 单价 数量 金额
产品1 2011-3-1 20 10 200
产品2 2011-3-2 20 20 400

合计: 30 600

查询条件可以按产品和时间来查询,可以给定一个时间段,然后根据 产品名称 ,单价,数量,金额分组查询,那样……


因为我是每天都发送产品给客户的,列数有限,按你这样排列的话,数据更是排不下 --------------------编程问答--------------------
引用 6 楼 ihandler 的回复:
每列显示一个产品? SQL 行转列呢?


SQL行专列也是固定行转为列啊, 我这个产品名称的列数是不固定的,它是根据客户订购的产品名来显示 --------------------编程问答-------------------- 你为什么要用前台  

直接拼repeater实现不了吗?

前台用行列控制
简单写个。

2011/3/1 10 0 0 0 
2011/3/2 0 10 0 0
20113/3 0 50 30 20
数量合计 10 60 30 20
单价(元) 2 3 4 5
合计 20 180 120 100

本月销售合计 420元
<tr><td>时间</td><td>产品1</td><td>产品2</td><td>产品3</td><td>产品4<td/><tr/>
<tr><td><%# Eval("时间")%></td><td><%# Eval("产品1")%></td><td><%# Eval("产品2")%></td><td><%# Eval("产品3")%></td><td><%# Eval("产品4")%></td><tr/>


<tr>单价<td></td><%# Eval("产品数量")%><td></td><td><%# Eval("产品数量")%></td><td><%# Eval("产品数量")%></td><td><%# Eval("产品数量")%></td><tr/>
<tr>合计<td></td><%= 字段乘积)%><td></td><td><%= 字段乘积)%></td><td><%= 字段乘积)%></td><td><%= 字段乘积)%></td><tr/>

<tr<td>本月销售合计</td><td><%= 合计字段%>元</td></tr>

后面凡是<%= 字段乘积)%>这样绑定 后台的必须声明一个变量

比如public static string str;
然后在下面进行赋值

在绑定<%= str)%>

这养既有字段 也有数据库中的字段就实现了。

没有环境随便写的。。

有错在改。
补充:.NET技术 ,  ASP.NET
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,