Repeater  控件可以数据库中的数据,一条条的查找出,不需要后端在进行遍历输出了,

Repeater必须使用的是Itemtemplate,其它的类型模板按需添加,主要记住Itemtemplate就行。

  ItemTemplate : 对每一个数据项进行格式设置
  AlternatingItemTemplate : 对交替数据项进行格式设置
  SeparatorTemplate : 对分隔符进行格式设置
  HeaderTemplate : 对页眉进行格式设置
  FooterTemplate : 对页脚进行格式设置

Repeater控件中的属性作用:

  DataBinding : Repeater控件绑定到数据源时触发
  ItemCommand : Repeater控件中的子控件触发事件时触发
  ItemCreated : 创建Repeater每个项目时触发
  ItemDataBound : Repeater控件的每个项目绑定数据时触发

HiddenField控件:  用于存储需要在向服务器的发送间保持的值

前端页面:

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="obgetest1.aspx.cs" Inherits="obgetest1" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title>遍历出省市</title>
<link rel="stylesheet" type="text/css" href="style/css.css" />
</head>
<body>
<form id="form1" runat="server">
<div>
<div class="xxlb_ss">
<ul> <asp:Repeater ID="RepeaterwxSheng" runat="server" OnItemDataBound="RepeaterwxSheng_ItemDataBound">
<ItemTemplate> <li>
<div class="middle" style="margin-bottom:20px;">
<div class="city_l"><span class="xxlb_ssbg" href=""><%# DataBinder.Eval(Container.DataItem,"Ext02") %></span></div>
<div class="city_r">
<asp:HiddenField ID="HiddenFieldShengCode" runat="server" Value='<%# DataBinder.Eval(Container.DataItem,"TypeCollCode") %>' />
<asp:Repeater ID="RepeaterwxShi" runat="server">
<ItemTemplate>
<a href=""><%# DataBinder.Eval(Container.DataItem,"Ext02") %></a>
</ItemTemplate>
</asp:Repeater>
</div>
<div class="clear"></div>
</div>
</li> </ItemTemplate>
</asp:Repeater> </ul>
</div>
</div>
</form>
</body>
</html>

对应后端:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls; public partial class obgetest1 :PageBase
{
//引用 逻辑层
private BllFourCollsType _bllCollType = new BllFourCollsType();
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
//调用省方法
ShengLoad();
}
} private void ShengLoad()
{
     //使用泛型从 对应model 表中寻找
List<FourCollsType> mList = _bllCollType.Get_Ex_FourCollsTypeListByIDLevel("TypeCollCode,Ext02", base.EnterpriseGuid, , , 0f);//rePeater 控件的省 RepeaterwxSheng 获取数据源
this.RepeaterwxSheng.DataSource = mList;
//绑定数据源
this.RepeaterwxSheng.DataBind();
} //
protected void RepeaterwxSheng_ItemDataBound(object sender, RepeaterItemEventArgs e)
{
//从省里面找市 所以需要隐藏域
HiddenField HiddenFieldShengCode = (HiddenField)e.Item.FindControl("HiddenFieldShengCode");
Repeater RepeaterwxShi = (Repeater)e.Item.FindControl("RepeaterwxShi");
if (RepeaterwxShi != null && HiddenFieldShengCode != null)
{ List<FourCollsType> mList = _bllCollType.Get_Ex_FourCollsTypeList_CodeDown("Ext02", base.EnterpriseGuid, , HiddenFieldShengCode.Value, , 0f);
//this 指的是当前页面对象,不能用 this
RepeaterwxShi.DataSource = mList;
RepeaterwxShi.DataBind();
}
}
}

ASP.NET ---- Repeater 遍历出省市的更多相关文章

  1. js中遍历出查询后的listmodel(下拉框系列)

    function selectclassname(){ $.ajax({ url:"queryschoolclasslists.action", async:false, data ...

  2. 每日学习心得:CustomValidator验证控件验证用户输入的字符长度、Linq 多字段分组统计、ASP.NET后台弹出confirm对话框,然后点击确定,执行一段代码

    2013-9-15 1.    CustomValidator验证控件验证用户输入的字符长度 在实际的开发中通常会遇到验证用户输入的字符长度的问题,通常的情况下,可以写一个js的脚本或者函数,在ASP ...

  3. [ASP.NET]asp.net Repeater控件的使用方法

    asp.net Repeater控件的使用方法 -- : 4770人阅读 评论() 收藏 举报 asp.netserveraspdatasetdeletexhtml 今天学习了,Repeater控件 ...

  4. asp.net中遍历界面上所有控件进行属性设置

    * 使用方法: *  前台页面调用方法,重置:    protected void Reset_Click(object sender, EventArgs e)        {           ...

  5. unity3d遍历出Cube里面所有子对象

     cube目录下有n个cube,可不可以一下子遍历出所有的对象,而不用一个一个的find?find(“Cube1”)   1.foreach(Transform ts in cube)   2.cub ...

  6. ASP.NET repeater添加序号列的方法

    ASP.NET repeater添加序号列的方法 1.<itemtemplate> <tr><td> <%# Container.ItemIndex + 1% ...

  7. ASP.NET根据IP获取省市地址

    1.在网站的跟路径下面添加 QQWry.dat 文件,这个文件是IP数据库文件 2.添加以下一个类 IPScanner     C# 代码   复制 public class IPScanner { ...

  8. vue.js 1.0中用v-for遍历出的li中的@click事件在移动端无效

    在vue.js使用v-for遍历出的li中的@click事件在移动端无效,在网页端可以执行,代码如下 <template> <div class="rating-secti ...

  9. Asp.net C# 遍历Excel中的表格名称

    Asp.net C# 遍历Excel中的表格名称     string strConn = "Provider=Microsoft.Jet.OLEDB.4.0;" + " ...

随机推荐

  1. Markdown语法教程

    标题 # 一级标题 ## 二级标题 ### 三级标题 #### 四级标题 ##### 五级标题 ###### 六级标题 效果如下: 一级标题 二级标题 三级标题 四级标题 五级标题 六级标题 段落 换 ...

  2. Could not open requirements file: [Errno 2] No such file or directory: 'requirements.txt

    最近安装python,已经安装好,cmd终端中输入python.pip等命令都有用 然而在配置requirements.txt文件过程中,执行语句 “pip install -r requiremen ...

  3. 【西北师大-2108Java】第十次作业成绩汇总

    [西北师大-2108Java]第十次作业成绩汇总 作业题目 面向对象程序设计(JAVA) 第12周学习指导及要求 实验目的与要求 (1)掌握Vetor.Stack.Hashtable三个类的用途及常用 ...

  4. JS数组去掉某一个元素

    /**数组去掉某一个元素**/ Array.prototype.remove = function(val) { var index = this.indexOf(val); if (index &g ...

  5. C# 对 Excel 的相关操作

    C# 对Excel的操作 学习自: 教练辅导 C# 对Excel的读取操作 我们需要额外添加引用: References 搜索Excel 这样我们的基础就添加完成了. 并且在using 中添加: us ...

  6. 【RTOS】为H7配套的uCOS-III模板也是可以用于MDK AC6的,提供个模板

    AC6模板 链接:https://pan.baidu.com/s/1_4z_Lg51jMT87RrRM6Qs3g   提取码:2gns 原始的这个模板直接修改为AC6: 编译有几十处警告,修改下面三个 ...

  7. C语言程序设计100例之(18):火柴棒等式

    例18   火柴棒等式 用n根火柴棍,可以拼出多少个形如“A+B=C”的等式?等式中的A.B.C是用火柴棒拼出的整数(若该数非零,则最高位不能是0).用火柴棒拼数字0~9的拼法如图1所示. 图1  用 ...

  8. C++如何使用宏定义来简化代码性能测试 | cpp macro like function to implement a performance profiler

    本文首发于个人博客https://kezunlin.me/post/65dc693d/,欢迎阅读最新内容! cpp macro like function to implement a perform ...

  9. kafka速度快的原因

    我们都知道Kafka非常快,比绝大多数的市场上其他消息中间件都要快.这里来研究下那么为什么Kafka那么快(当然不会是因为它用了Scala). Kafka的消息是保存或缓存在磁盘上的,一般认为在磁盘上 ...

  10. docker中安装宝塔面板

    我的电脑是win10,安装的virtualbox其上装的ubutun14,ubutun也安装了docker,今天我补充一个完整的操作流程.怎么在docker中安装宝塔面板?先打个岔,这些命令总是记不住 ...