Repeater 绑定下拉列表
1. 这几天在做一个项目用到了Repeater,这个在网上说的可能不太多。因本人用到Repeater中绑定下拉列表实现方式如下。
在repeater上抓取控件及进行数据绑定大致分为两种:
(一种情况为:)
第一种在数据手动绑定后用for循环来查找下拉列表控件(其它控件原理一样)
代码如下:
前台代码大致为:
<asp:Repeater ID="rptList" runat="server" OnItemDataBound="rptList_ItemDataBound">
<HeaderTemplate>
<table width="100%" border="0" cellspacing="0" cellpadding="0" class="msgtable">
<tr>
.
.
.
<th width="12%" align="left">下拉列表</th>
.
.
.
</tr>
</HeaderTemplate>
<ItemTemplate>
<tr>
.
.
.
<td><asp:DropDownList ID="ddlManager" runat="server" CssClass="select required"> </asp:DropDownList></td>
.
.
.
</tr>
</ItemTemplate>
</asp:Repeater>
后台代码:
private void DateBindView()
{
DataSet ds = 结果集合获得的方法,返回来的数据为DataSet类型。
// rptList为前台repeater的ID
rptList.DataSource = ds;
rptList.DataBind();
// 定义一个列表
DropDownList dllExample;
for (int j = 0; j < this.rptContent.Items.Count; j++)
{
dllExample= (DropDownList)this.rptContent.Items[j].FindControl("ddlManager");
dllExample.DataSource = BLL.StateInfoManager.GetList().Tables[0].DefaultView;
dllExample.DataTextField = "绑定的下拉列表名称";
dllExample.DataValueField = "绑定下拉列表的ID";
dllExample.DataBind();
DataRowView rowv = (DataRowView)this.rptContent.Items[j].DataItem;
//设置初始项
dllExample.Items.Add(new ListItem("-选择-", ""));
//获到当前列的状态ID用于绑定下拉列表
dllExample.SelectedValue = ds.Tables[0].Rows[j][绑定的下拉列表ID].ToString();
}
}
第一种方法就写完了。
第二种方法:
temDataBound方法中进行查找下拉列表,并进行当前数据的绑定.
前台还是如上:不过多了一个方法为:temDataBound 既: OnItemDataBound="rptList_ItemDataBound"
后台有所不同代码如下:
protected void rptList_ItemDataBound(object sender, RepeaterItemEventArgs e)
{
if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
{
DropDownList dllExample= (DropDownList)e.Item.FindControl("ddlManager");
dllExample.DataTextField = "Remark";
dllExample.DataValueField = "stateid";
dllExample.DataSource = 获得的数据集合。(集合DATAset)
dllExample.DataBind();
dllExample.Items.Add(new ListItem("-Choose-", ""));
//找到分类Repeater关联的数据项
DataRowView rowv = (DataRowView)e.Item.DataItem;//获取当前项行数据再去访问那一列.注意坐标索引是从0开始
dllExample.SelectedValue =rowv[绑定的下拉列表ID列号].ToString();
}
}
希望对大家有所帮助。
转载于:https://www.cnblogs.com/northeastTycoon/archive/2012/10/23/Repeater%E7%BB%91%E5%AE%9A%E4%B8%8B%E6%8B%89%E5%88%97%E8%A1%A8.html
Repeater 绑定下拉列表相关推荐
- Repeater绑定ArrayList数据源
Repeater绑定ArrayList数据源 就相当与把ArrayList的数据绑定到Repeater的ItemTemplate 上 就是RepeaterItem等于ArrayList的一项例如 Me ...
- 一个可行的绑定下拉列表的方法(bind dropdownlist)
//绑定command类型的下拉列表//传入一个IList<T>类型的数据 name.i是绑定项 public List<SelectListItem> bindDropLis ...
- C# Repeater绑定显示数组
此处绑定的对象拥有string[] Contents属性,绑定时将Contents[0]和Contents[1]分别绑定 <asp:Repeater runat="server&quo ...
- linq绑定下拉列表,combobox中增加listitem的方法,增加“请选择”
第一步:自定义一个类ListItem public class ListItem { private string text = string.Empty; p ...
- Repeater绑定事件ItemDataBound中获取数据库中数据
protected void rp1_ItemDataBound(object sender, RepeaterItemEventArgs e) { if (e.Item.ItemTy ...
- Repeater 嵌套 绑定数据,嵌套的Repeater无法绑定的问题
Repeater 嵌套 绑定数据,嵌套的Repeater无法绑定的问题 今天做绑定遇到了这个么个问题,绑定的事件ItemDataBound()跟之前的并没有 改动,为什么会出现绑定失败的问题呢?要是你 ...
- Repeater控件使用小结持续更新
Repeater嵌套Repeater绑定数据 前台代码 1 <!--注意层级关系不要写错了--> 2 <asp:Repeater ID="rpGroup" run ...
- .net Repeater知识知多少
(一).net中使用Repeater绑定数据,并使用repeater循环出的两个值,赋给repeater中的div的value值.详细如下: 前端.net代码: <div class=" ...
- repeater导出excel html,Repeater显示数据,并且导出到excel
我的数据是自己手工生产,然后repeater绑定,最后导出excel,但出现问题,谁可以给个例子什么的没有. 关键代码如下: protected void LinkButton1_Click(obje ...
最新文章
- SPOJ Pattern Find(Rabin Karp)
- 2011-05-20
- SpringBoot创建SpringBoot项目以及启动器讲解
- 快钱如何快-企业级效率提升实践
- NumPy 生成全0矩阵,全1矩阵,随机矩阵,求平均数,求方差的方法
- mysql 更新索引_MySQL索引优化
- @ResponseBody//该注解会将返回值转为json格式并放到响应体中返回到前台
- 啥是Attention?
- 自顶向下 计算机网络知识,计算机网络(自顶向下)第七版考试复习要点(第四章)...
- Python取整(四舍五入、向上取整、向下取整)
- 【kibana】状态异常 Status: Red Status changed from red to yellow - No existing Kibana index found
- maven junit空指针_Maven相关笔试面试题目
- Android开发笔记(一百五十三)OpenGL绘制三维图形的流程
- 为什么我一再强调说新手创业不适合再开淘宝店?
- Reddit 评级算法的工作原理
- python与excel-Python与Excel(1)
- Atitit 企业战略目标的艺术 目录 1. 企业战略目标	1 2. 特点 ▪ 宏观性 ▪ 长期性 ▪ 全面性 稳定性	1 3. 内容	2 3.1. 彼得·德鲁克在《管理实践》一书中提出了八个
- 笨方法学Python笔记(5)
- 添加内核驱动模块(3)(mydriver.c+ Konfig+Makefile )
- 阿里云Ubuntu系统部署K8s集群
热门文章
- 虚拟机3种网络模式(桥接、nat、Host-only)
- php简单的mysql类_一个简单的php mysql操作类
- python实时数据流设计_Python读取实时数据流示例
- python构建二维数组_Python中创建二维数组
- SUID + SGID + STICKY
- 休眠 关闭串口输出_C#实例:串口通讯
- el表达式动态取值中括号内两点_中考热点:旧瓶新酒,解题新策略分析之玩转动态型热点题型...
- 四针手表指的是什么_1000~1500元的男士手表推荐
- 克隆管理员帐号的方法
- 如何在MFC线程中使用控件的成员变量和函数