Asp.net Repeater控件实现一行显示多条数据

Asp.net Repeater控件实现一行显示多条数据
       asp.net中Repeater控件可以很方便显示数据库的数据,使用传统的Table来布局,只能实现一行显示数据库中一条数据,如果需一行显示数据库中多条数据,我们可以使用Div的浮动布局(float:left|right)很方便的实现这一效果 。
代码如下: 
       
<% @ Page Language = " C# "  AutoEventWireup = " true "  CodeFile = " Default4.aspx.cs "  Inherits = " Default4 "   %>  
<! DOCTYPE html PUBLIC  " -//W3C//DTD XHTML 1.0 Transitional//EN "   " http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd " >  
< html xmlns = " http://www.w3.org/1999/xhtml "   >  
< head runat = " server " >  
    
< title > Repeater控件实现一行显示多条数据 </ title >  
    
< style type = " text/css " >  
        #content 
        

            border:1px solid #CCCCCC; 
            width:600px; 
            text
-align:left; 
        }
 
        #list 
        

            width:200px; 
            
float:left;             
        }
 
    
</ style >  
</ head >  
< body >  
    
< form id = " form1 "  runat = " server " >  
    
< div >  
    
< asp:SqlDataSource ID = " SqlDataSource1 "  runat = " server "  C SelectCommand = " SELECT * FROM [User] " ></ asp:SqlDataSource >  
    
< asp:Repeater runat = " server "  ID = " tt "  DataSourceID = " SqlDataSource1 " >  
            
< HeaderTemplate >  
                
< div id = " content " >  
            
</ HeaderTemplate >  
            
< ItemTemplate >  
                
< div id = " list " >  
                    
< ul >  
                        
< li > Id: <% #Eval( " Id " %></ li >  
                        
< li > Name: <% #Eval( " Name " %></ li >  
                        
< li > Sex: <% #Eval( " Sex " %></ li >  
                        
< li > Tel: <% #Eval( " Tel " %></ li >  
                    
</ ul >  
                
</ div >                
            
</ ItemTemplate >  
            
< FooterTemplate >  
                
</ div >  
            
</ FooterTemplate >  
        
</ asp:Repeater >  
    
</ div >  
    
</ form >  
</ body >  
</ html >

你可能感兴趣的:(asp.net)