关于asp.net 控件repeater的问题
我正在练习使用repeater控件的itemtemplate,在repeater控件中显示自定义的ArrayList数组中的值。用的是C#。page_load添加代码如下...
我正在练习使用repeater控件的itemtemplate,在repeater控件中显示自定义的ArrayList数组中的值。用的是C#。page_load添加代码如下:
if(!IsPostBack)
{
ArrayList Cities=new ArrayList();
Cities.Add("beijing");
Cities.Add("shanghai");
Cities.Add("nanjing");
Cities.Add("jinan");
Repeater1.DataSource=Cities;
Repeater1.DataBind();
}
在html视图中添加代码如下:
<asp:Repeater id="Repeater1" runat="server">
<ItemTemplate>
<%#Container.DataItem%>
</ItemTemplate>
</asp:Repeater>
可是运行之后页面上什么也没有,请教高手这是什么原因? 展开
if(!IsPostBack)
{
ArrayList Cities=new ArrayList();
Cities.Add("beijing");
Cities.Add("shanghai");
Cities.Add("nanjing");
Cities.Add("jinan");
Repeater1.DataSource=Cities;
Repeater1.DataBind();
}
在html视图中添加代码如下:
<asp:Repeater id="Repeater1" runat="server">
<ItemTemplate>
<%#Container.DataItem%>
</ItemTemplate>
</asp:Repeater>
可是运行之后页面上什么也没有,请教高手这是什么原因? 展开
展开全部
前台代码
<%@ 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">
<ItemTemplate>
<%#Container.DataItem%>
</ItemTemplate>
</asp:Repeater>
</div>
</form>
</body>
</html>
后台代码
using System;
using System.Data;
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;
using System.Collections;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
ArrayList Cities = new ArrayList();
Cities.Add("beijing");
Cities.Add("shanghai");
Cities.Add("nanjing");
Cities.Add("jinan");
Repeater1.DataSource = Cities;
Repeater1.DataBind();
}
}
}
我调试过去了,你再看看。要用datalist需要程序集using System.Collections;
<%@ 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">
<ItemTemplate>
<%#Container.DataItem%>
</ItemTemplate>
</asp:Repeater>
</div>
</form>
</body>
</html>
后台代码
using System;
using System.Data;
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;
using System.Collections;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
ArrayList Cities = new ArrayList();
Cities.Add("beijing");
Cities.Add("shanghai");
Cities.Add("nanjing");
Cities.Add("jinan");
Repeater1.DataSource = Cities;
Repeater1.DataBind();
}
}
}
我调试过去了,你再看看。要用datalist需要程序集using System.Collections;
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询