Repeater控件为什么啥也不显示呢
为什么啥也不显示,连Header里的文字也不显示
.aspx代码:
<%@ Page Language= "C# " AutoEventWireup= "true " CodeFile= "Default.aspx.cs " Inherits= "_Default " %>
<!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:HeaderTemplate>
<table>
<tr>
<td>
编号 </td>
<td>
身份证号码 </td>
<td>
姓名 </td>
</tr>
</asp:HeaderTemplate>
<asp:ItemTemplate>
<tr>
<td>
<asp:Label runat= "server " ID= "bianhao " Text= ' <%# Eval( "员工编号 ") %> '/>
</td>
<td>
<asp:Label runat= "server " ID= "shenfenzheng " Text= ' <%# Eval( "身份证号码 ") %> '/>
</td>
<td>
<asp:Label runat= "server " ID= "xingming " Text= ' <%# Eval( "学生姓名 ") %> '/>
</td>
</tr>
</asp:ItemTemplate>
<asp:FooterTemplate>
</table> </asp:FooterTemplate>
</asp:Repeater>
</div>
</form>
</body>
</html>
.cs代码:
using System;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
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;
public partial class _Default : System.Web.UI.Page
{
string ConStr = (string)ConfigurationManager.ConnectionStrings[ "9957_PRODUCT_SMSConnectionString "].ConnectionString;
protected void Page_Load(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection(ConStr);
SqlCommand com=new SqlCommand( "select * from 学生 ",con);
con.Open();
SqlDataReader dr=com.ExecuteReader();
Repeater1.DataSource = dr;
Repeater1.DataBind();
con.Close();
}
}
[解决办法]
<asp:ItemTemplate>
有ASP和没ASP一样吗?
去掉行不行?
[解决办法]
<asp:ItemTemplate> 改成 <ItemTemplate>
应该是不需要前面的asp:
<HeaderTemplate>
<table>
<tr>
<td>
编号 </td>
<td>
身份证号码 </td>
<td>
姓名 </td>
</tr>
<HeaderTemplate>