- 爱易网页
-
ASP.NET教程
- 白送分的有关问题
日期:2014-05-19 浏览次数:20463 次
白送分的问题
我是新手,我想用repeater 显示数据库里面的数据,但是结果是不报错,也不显示
aspx代码:
<%@ Page Language= "C# " AutoEventWireup= "true " CodeFile= "user.aspx.cs " Inherits= "xuexi_user " %>
<!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>
<asp:Repeater ID= "Repeater1 " runat= "server ">
</asp:Repeater>
</div>
</form>
</body>
</html>
cs代码:
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 xuexi_user : System.Web.UI.Page
{
string Con_str;
protected void Page_Load(object sender, EventArgs e)
{
Con_str = ConfigurationSettings.AppSettings[ "SQL_dsn "];
SqlConnection Scon = new SqlConnection(Con_str);
SqlDataAdapter Sds = new SqlDataAdapter( "select * from authors ",Scon);
DataSet Ds = new DataSet();
Sds.Fill(Ds, "authors ");
Repeater1.DataSource = Ds.Tables[ "authors "];
Repeater1.DataBind();
Scon.Close();
Scon.Dispose();
}
}
------解决方案--------------------
Repeater控件本来就没有界面,你要自己写嘛
<asp:Repeater ....>
<HeaderTemplate>
//这里写头
</HeaderTemplate>
<ItemTemplate>
//这里写循环
</ItemTemplate>
<FooterTemplate>
//这里写尾
</FooterTemplate>
</asp:Repeater>
------解决方案--------------------