原文发布时间为:2009-05-11 —— 来源于本人的百度文章 [由搬家工具导入]
asp.net中Repeater控件可以很方便显示数据库的数据,使用传统的Table来布局,只能实现一行显示数据库中一条数据,如果需一行显示数据库中多条数据,我们可以使用Div的浮动布局(float:left|right)很方便的实现这一效果 。
代码简要说明:以下代码一行将显示 3 条数据,why?? 因为跟那个CSS有关系。。。600 200 600÷200=3 条

代码如下:

<%@ 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;

600px;

text-align:left;

}

#list


{

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>