</table> </div> </form> </body> </html> 后台: using System; using System.Data; using System.Configuration; using System.Collections; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Web.UI.HtmlControls; using System.Data.SqlClient;public partial class Default2 : System.Web.UI.Page { private void bindAuthors() { SqlConnection Conn = new SqlConnection(); System.Configuration.AppSettingsReader app = new AppSettingsReader(); Conn.ConnectionString = app.GetValue("ConnString", typeof(string)).ToString(); Conn.Open(); string sql = "select phone from authors"; SqlDataAdapter ada = new SqlDataAdapter(); SqlCommand com = new SqlCommand(sql, Conn); ada.SelectCommand = com; DataSet ds = new DataSet(); ada.Fill(ds, "authors"); if(ds.Tables["authors"].Rows.Count>0) { DataTable dt ; HtmlTableRow tr; HtmlTableCell tc; CheckBox cb; dt = ds.Tables["authors"]; for (int i = 0; i < dt.Rows.Count; i = i + 10) { tr = new HtmlTableRow();
int j=0;
for(int i=0;i<dt.rows.count;i=i+10)
{
test="记录一"+dt.row(i+1)("字段")+"记录二"+dt.row(i+2)("字段")+".........";
}
DataList,有一个RepeatDirection属性可以设置绑定数据是横向排列还是竖向排死
还有一个RepeatColumns可以设置横向显示的列数。
你把
System.Configuration.AppSettingsReader app = new AppSettingsReader();
Conn.ConnectionString = app.GetValue("ConnString", typeof(string)).ToString();
这个换成你的联接串就可以了
前台:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default2.aspx.cs" Inherits="Default2" %><!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>无标题页</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<table id="auTable" runat="server" border="1">
</table>
</div>
</form>
</body>
</html>
后台:
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;public partial class Default2 : System.Web.UI.Page
{ private void bindAuthors()
{
SqlConnection Conn = new SqlConnection();
System.Configuration.AppSettingsReader app = new AppSettingsReader();
Conn.ConnectionString = app.GetValue("ConnString", typeof(string)).ToString();
Conn.Open();
string sql = "select phone from authors";
SqlDataAdapter ada = new SqlDataAdapter();
SqlCommand com = new SqlCommand(sql, Conn);
ada.SelectCommand = com;
DataSet ds = new DataSet(); ada.Fill(ds, "authors");
if(ds.Tables["authors"].Rows.Count>0)
{
DataTable dt ;
HtmlTableRow tr;
HtmlTableCell tc;
CheckBox cb;
dt = ds.Tables["authors"];
for (int i = 0; i < dt.Rows.Count; i = i + 10)
{
tr = new HtmlTableRow();
for (int j = 0; j < 10; j++)
{
tc = new HtmlTableCell();
cb = new CheckBox();
tc.InnerText = dt.Rows[i][0].ToString();
tc.Controls.Add(cb);
tr.Cells.Add(tc);
}
auTable.Rows.Add(tr);
}
}
//GridView1.DataSource = ds.Tables["authors"].DefaultView;
//GridView1.DataBind();
} protected void Page_Load(object sender, EventArgs e)
{
if(!Page.IsPostBack)
{
bindAuthors();
}
}
}
<asp:Repeater ID="ListBody" Runat="server">
<ItemTemplate>
<td width="10%">
<table border="0" cellpadding="0" cellspacing="0" width="100%">
<tr><td>xxxx</td></tr>
</table>
</td>
</ItemTemplate>
</asp:Repeater>后台cs页面
private void ListBody_ItemDataBound(object sender, RepeaterItemEventArgs e)
{
if (e.Item.ItemIndex % 10 ==1)
this.ListBody.Controls.Add(new TableRow());
}
CheckBoxList是最简单的选择