多级分类统计列表ListView实现

由于学校火车订票系统需要按学院班级统计票数和钱数。实现如下图所示列表。以下直奔主题。

1

aspx页面部分代码:
 
 
   
代码
    
      
< asp:SqlDataSource ID = " SqlDataSource1 " runat = " server "
ConnectionString
= " <%$ ConnectionStrings:TrainConnectionString %> " >
</ asp:SqlDataSource >
< div style = " color:#4C4847;font-size:16px;margin:0 auto;text-align:center;padding:10px;font-weight:bold; " >

福州大学火车订票系统
- 订票明细表( <%= DateTime.Now.ToShortDateString() %> </ div >
< asp:ListView ID = " lsvAcademe " runat = " server " DataSourceID = " SqlDataSource1 " DataKeyNames = " AcademeID " >
< EmptyDataTemplate >
< div style = " color:red;font-size:16px;margin:0 auto;text-align:center; " > 对不起,没有找到您想要的数据! </ div >
</ EmptyDataTemplate >
< LayoutTemplate >
< table class = " order-list-table " >
< tr >
< th > 学院 </ th >< th > 票数 </ th >< th > 硬座总价 </ th >< th > 预收总价 </ th >
< th > 班级 </ th >< th > 票数 </ th >< th > 硬座总价 </ th >< th > 预收总价 </ th >
< tr >
< asp:PlaceHolder ID = " itemPlaceHolder " runat = " server " ></ asp:PlaceHolder >
< td colspan = " 8 " style = " height:0; " ></ td >
</ tr >
</ table >
</ LayoutTemplate >
< ItemTemplate >
< td rowspan = ' <%# Eval("ClassCount") %> ' ><% # Eval( " Academe " ) %></ td >
< td rowspan = ' <%# Eval("ClassCount") %> ' ><% # Eval( " TicketCount " ) %></ td >
< td rowspan = ' <%# Eval("ClassCount") %> ' ><% # String.Format( " {0:0.0} " ,Eval( " HardseatTotal " )) %></ td >
< td rowspan = ' <%# Eval("ClassCount") %> ' ><% # String.Format( " {0:0.0} " ,Eval( " AdvanceTotal " )) %></ td >
< uc1:ListViewClass ID = " ListViewClass1 " runat = " server " AcademeID = ' <%#Eval("AcademeID") %> ' />
</ ItemTemplate >
</ asp:ListView >


其中我用到了Listview控件的嵌套,但是我将其分离为一个独立的用户控件。
控件的显示代码:


代码



    
      
< asp:ListView runat = " server " ID = " lsvClass " DataSourceID = " SqlDataSource1 " >
< LayoutTemplate >
< asp:PlaceHolder ID = " itemPlaceHolder " runat = " server " ></ asp:PlaceHolder >
</ LayoutTemplate >
< ItemTemplate >
< td ><% #Eval( " ClassName " ) %></ td >
< td ><% #Eval( " TicketCount " ) %></ td >
< td ><% #String.Format( " {0:0.0} " ,Eval( " HardSeatTotal " )) %></ td >
< td ><% #String.Format( " {0:0.0} " ,Eval( " AdvanceTotal " )) %></ td ></ tr >< tr >
</ ItemTemplate >
</ asp:ListView >

< asp:SqlDataSource ID = " SqlDataSource1 " runat = " server "
ConnectionString
= " <%$ ConnectionStrings:TrainConnectionString %> "
SelectCommand
= " SELECT * FROM [V_DetailOrderListForClass] " ></ asp:SqlDataSource >


控件的cs页面代码:

代码



    
      
namespace Website.Controls
{
public partial class ListViewClass : System.Web.UI.UserControl
{
private string academeID;
public string AcademeID
{
set { academeID = value; }
}
protected void Page_Load( object sender, EventArgs e)
{
SqlDataSource1.SelectCommand
= " SELECT * From [V_DetailOrderListForClass] where AcademeID=@AcademeID " ;
SqlDataSource1.SelectParameters.Add(
" AcademeID " ,System.TypeCode.Int32, academeID);
lsvClass.DataBind();
}
}
}


这次火车订票系统的多表之间联合查询非常频繁,有的甚至为了实现某个统计功能,经过查询多个视图(视图再查询视图),我想
这个性能消耗挺大的。

你可能感兴趣的:(ListView)