asp.net中的repeater控件 如何使用
4个回答
2011-07-06
展开全部
<table>
<tr>
<td style="width:120px" align="center">
班级名称</td>
<td style="width:120px" align="center">
开班时间</td>
<td style="width:120px" align="center">
状态</td>
</tr>
<tr>
<td colspan="3">
<asp:Repeater ID="Repeater1" runat="server">
<ItemTemplate>
<table cellpadding="0" cellspacing="0" style="width:550px;height:135px">
<tr>
<td style="width:120px" align="center">
<asp:Label ID="Label1" runat="server" Text='<% #Eval("班级名称字段名")%>'>
</asp:Label><%--显示班级名称--%>
</td>
<td style="width:120px" align="center">
<asp:Label ID="Label2" runat="server" Text='<% #Eval("开班时间字段名")%>'>
</asp:Label><%--显示开班时间--%>
</td>
<td style="width:120px" align="center">
<asp:Label ID="Label3" runat="server" Text='<% #Eval("状态字段名")%>'>
</asp:Label><%--显示状态--%>
</td>
</tr>
</table>
</ItemTemplate>
</asp:Repeater>
</td>
</tr>
</table>
<%--##字段名为数据库中的字段名--%>
//表格的宽度,样式等自己控制好
后台绑定数据:
……
//查到的数据绑定到DataSet 控件
DataSet ds = new DataSet("ntable");
adapter.Fill(ds, "ntable");
Repeater1.DataSource = ds.Tables["ntable"];
Repeater1.DataBind();
conn.Close(); //关闭连接
以上代码仅供参考,如需帮助—qq:281966747(请注明:百度知道)
另外,虚机团上产品团购,超级便宜
<tr>
<td style="width:120px" align="center">
班级名称</td>
<td style="width:120px" align="center">
开班时间</td>
<td style="width:120px" align="center">
状态</td>
</tr>
<tr>
<td colspan="3">
<asp:Repeater ID="Repeater1" runat="server">
<ItemTemplate>
<table cellpadding="0" cellspacing="0" style="width:550px;height:135px">
<tr>
<td style="width:120px" align="center">
<asp:Label ID="Label1" runat="server" Text='<% #Eval("班级名称字段名")%>'>
</asp:Label><%--显示班级名称--%>
</td>
<td style="width:120px" align="center">
<asp:Label ID="Label2" runat="server" Text='<% #Eval("开班时间字段名")%>'>
</asp:Label><%--显示开班时间--%>
</td>
<td style="width:120px" align="center">
<asp:Label ID="Label3" runat="server" Text='<% #Eval("状态字段名")%>'>
</asp:Label><%--显示状态--%>
</td>
</tr>
</table>
</ItemTemplate>
</asp:Repeater>
</td>
</tr>
</table>
<%--##字段名为数据库中的字段名--%>
//表格的宽度,样式等自己控制好
后台绑定数据:
……
//查到的数据绑定到DataSet 控件
DataSet ds = new DataSet("ntable");
adapter.Fill(ds, "ntable");
Repeater1.DataSource = ds.Tables["ntable"];
Repeater1.DataBind();
conn.Close(); //关闭连接
以上代码仅供参考,如需帮助—qq:281966747(请注明:百度知道)
另外,虚机团上产品团购,超级便宜
展开全部
用来绑定列表或其它数据的.如:
CS:
DataTable dt = new DataTable();
dt.Columns.Add(new DataColumn("id", typeof(string)));
dt.Columns.Add(new DataColumn("name", typeof(string)));
for (int ii = 1; ii < 11; ii++) {
DataRow newDr = dt.NewRow();
newDr["id"] = ii;
newDr["name"] = "my name is "+ii;
dt.Rows.Add(newDr);
}
this.rtData.DataSource = dt;
this.rtData.DataBind();
ASPX:
<table>
<tr>
<td style="width:200px;">id</td>
<td style="width:200px;">name</td>
</tr>
<asp:Repeater ID="rtData" runat="server">
<ItemTemplate>
<tr>
<td><%# Eval("id")%></td>
<td><%# Eval("name")%></td>
</tr>
</ItemTemplate>
</asp:Repeater>
</table>
CS:
DataTable dt = new DataTable();
dt.Columns.Add(new DataColumn("id", typeof(string)));
dt.Columns.Add(new DataColumn("name", typeof(string)));
for (int ii = 1; ii < 11; ii++) {
DataRow newDr = dt.NewRow();
newDr["id"] = ii;
newDr["name"] = "my name is "+ii;
dt.Rows.Add(newDr);
}
this.rtData.DataSource = dt;
this.rtData.DataBind();
ASPX:
<table>
<tr>
<td style="width:200px;">id</td>
<td style="width:200px;">name</td>
</tr>
<asp:Repeater ID="rtData" runat="server">
<ItemTemplate>
<tr>
<td><%# Eval("id")%></td>
<td><%# Eval("name")%></td>
</tr>
</ItemTemplate>
</asp:Repeater>
</table>
本回答被提问者和网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
<asp:Repeater ID="Repeater1" runat="server">
<ItemTemplate>
<li><span class="listleft"><a href="newsArticle.aspx?pId=<%#Eval("id") %>&pinId=<%#Eval("classId.ID") %>" title='<%#Eval("title") %>'><%# StringHandler.CutString( Eval("title").ToString(),24) %></a></span><span class="listright"><%#Eval("adddate") %></span></li>
</ItemTemplate>
</asp:Repeater>
IList<News> news = DBHelperNews.GetAllNews("", " and ClassId=" + pinpaiid);
PagedDataSource pdslist = new PagedDataSource();
pdslist.DataSource = news;
if (news.Count > 0)
{
pdslist.AllowPaging = true;
pdslist.PageSize = this.AspNetPager1.PageSize;//取控件的分页大小
pdslist.CurrentPageIndex = this.AspNetPager1.CurrentPageIndex - 1;
this.AspNetPager1.RecordCount = news.Count;
this.Repeater1.DataSource = pdslist;
this.Repeater1.DataBind();
}
else
{
this.Repeater1.DataSource = "";
this.Repeater1.DataBind();
}
<ItemTemplate>
<li><span class="listleft"><a href="newsArticle.aspx?pId=<%#Eval("id") %>&pinId=<%#Eval("classId.ID") %>" title='<%#Eval("title") %>'><%# StringHandler.CutString( Eval("title").ToString(),24) %></a></span><span class="listright"><%#Eval("adddate") %></span></li>
</ItemTemplate>
</asp:Repeater>
IList<News> news = DBHelperNews.GetAllNews("", " and ClassId=" + pinpaiid);
PagedDataSource pdslist = new PagedDataSource();
pdslist.DataSource = news;
if (news.Count > 0)
{
pdslist.AllowPaging = true;
pdslist.PageSize = this.AspNetPager1.PageSize;//取控件的分页大小
pdslist.CurrentPageIndex = this.AspNetPager1.CurrentPageIndex - 1;
this.AspNetPager1.RecordCount = news.Count;
this.Repeater1.DataSource = pdslist;
this.Repeater1.DataBind();
}
else
{
this.Repeater1.DataSource = "";
this.Repeater1.DataBind();
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
囧 那么多控件里 就这个会用....~
情何以堪
只要在里面写代码 他会根据你datasource的size循环的
然后eval就可以了
情何以堪
只要在里面写代码 他会根据你datasource的size循环的
然后eval就可以了
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询