ASP.NET ---- Repeater 遍历出省市
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 遍历出省市的更多相关文章
- js中遍历出查询后的listmodel(下拉框系列)
function selectclassname(){ $.ajax({ url:"queryschoolclasslists.action", async:false, data ...
- 每日学习心得:CustomValidator验证控件验证用户输入的字符长度、Linq 多字段分组统计、ASP.NET后台弹出confirm对话框,然后点击确定,执行一段代码
2013-9-15 1. CustomValidator验证控件验证用户输入的字符长度 在实际的开发中通常会遇到验证用户输入的字符长度的问题,通常的情况下,可以写一个js的脚本或者函数,在ASP ...
- [ASP.NET]asp.net Repeater控件的使用方法
asp.net Repeater控件的使用方法 -- : 4770人阅读 评论() 收藏 举报 asp.netserveraspdatasetdeletexhtml 今天学习了,Repeater控件 ...
- asp.net中遍历界面上所有控件进行属性设置
* 使用方法: * 前台页面调用方法,重置: protected void Reset_Click(object sender, EventArgs e) { ...
- unity3d遍历出Cube里面所有子对象
cube目录下有n个cube,可不可以一下子遍历出所有的对象,而不用一个一个的find?find(“Cube1”) 1.foreach(Transform ts in cube) 2.cub ...
- ASP.NET repeater添加序号列的方法
ASP.NET repeater添加序号列的方法 1.<itemtemplate> <tr><td> <%# Container.ItemIndex + 1% ...
- ASP.NET根据IP获取省市地址
1.在网站的跟路径下面添加 QQWry.dat 文件,这个文件是IP数据库文件 2.添加以下一个类 IPScanner C# 代码 复制 public class IPScanner { ...
- vue.js 1.0中用v-for遍历出的li中的@click事件在移动端无效
在vue.js使用v-for遍历出的li中的@click事件在移动端无效,在网页端可以执行,代码如下 <template> <div class="rating-secti ...
- Asp.net C# 遍历Excel中的表格名称
Asp.net C# 遍历Excel中的表格名称 string strConn = "Provider=Microsoft.Jet.OLEDB.4.0;" + " ...
随机推荐
- Fail-fast
实际上,java.util.Iterator 的大多数实现都提供了故障快速修复(Fail-fast)的机制 ⎯⎯在利用迭代器遍历某一容器的过程中,一旦发现该容器的内容有所改变,迭代器就会抛出 Conc ...
- Mac-无法进入mysql,你这样做就对了
mysql -uroot -p 输入密码之后报错:ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using passwo ...
- laravel实现多模块
一.这里使用Caffienate Modules 网址:modules maintained by caffeinated 二.根据自己的版本选择包的版本 三.在项目composer.json文件中加 ...
- 【OCR技术系列之四】基于深度学习的文字识别
上一篇提到文字数据集的合成,现在我们手头上已经得到了3755个汉字(一级字库)的印刷体图像数据集,我们可以利用它们进行接下来的3755个汉字的识别系统的搭建.用深度学习做文字识别,用的网络当然是CNN ...
- 判断上传的Excel为.xlsx还是.xls
这个问题其实蛮简单的,具体操作如下 判断获取到上传的文件id后下载文件,然后拿到文件名称,截取文件名称后缀,判断是.xlsx还是.xls进行不同的操作即可
- linux命令-挂载命令
一.挂载命令 1.mount 命令基本格式 linux 所有存储设备都必须挂载使用,包括硬盘 命令名称:mount 命令所在路径:/bin/mount 执行权限:所有用户 [root@localhos ...
- ros2中创建一个python package
完整的python package的目录结构如下: source /opt/ros/dashing/setup.bash cd ros2_ws/src && ros2 pkg crea ...
- 转:C# String为值类型还是引用类型
关于String为值类型还是引用类型的讨论一直没有平息,最近一直在研究性能方面的问题,今天再次将此问题进行一次明确.希望能给大家带来点帮助,如果有错误请指出. 来看下面例子: //值类型 int a ...
- 【SDUT】2019SDUTACM第一次选拔赛 F- X的追求道路
Problem Description X在大家的帮助下终于找到了一个妹纸,于是开始了漫漫的追求之路,那么大家猜一猜X能不能追的上呢? X初始对妹纸有一个心动值,妹纸对X有一个好感值,在追求时发生的的 ...
- SQL实用技巧:如何将表中某一列的部分数据合并到一行中
select *,stuff(select ‘,’ + fieldname from table1 for xml path(”)),1,1,”) as field from table2 for ...