Repeater 实现 OnSelectedIndexChanged
在Repeater中使用DropDownList的方法
在Repeater中使用DropDownList的方法
以下代码并不完整,只记录了关键的方法
aspx代码中
假设这是一个用户管理的系统的模型,有一个下拉菜单来操作用户状态
<asp:Repeater ID="RepeaterArticleList" runat="server" onitemdatabound="RepeaterArticleList_ItemDataBound"> <ItemTemplate> <asp:HiddenField ID="HiddenField1" Value=<%#Eval("ID") %> runat="server" /> <asp:DropDownList ID="droplist1" runat="server" OnSelectedIndexChanged="DropDownList1_Change" AutoPostBack="true" > <asp:ListItem Text="启用" Value="1"></asp:ListItem> <asp:ListItem Text="禁用" Value="2"></asp:ListItem> <asp:ListItem Text="删除" Value="3"></asp:ListItem> </asp:DropDownList> </ItemTemplate> </asp:Repeater> |
cs代码中对应的DropDownList1_Change方法,取到用户ID,执行操作

protected void DropDownList1_Change(object sender, EventArgs e)
{
DropDownList drd = sender as DropDownList;
Repeater rps = drd.Parent.Parent as Repeater;
int n = ((RepeaterItem)drd.Parent).ItemIndex;
HiddenField hid = (HiddenField)(rps.Items[n].FindControl("HiddenField1"));
string userid= hid.Value;
string userState = Convert.ToInt32(drd.SelectedValue); //已经拿到了id,可以进行操作 YourFunction(userid,userState);
}

在前台显示的时候,再根据用户的状态值,来选择下拉菜单的默认选中值首先为RepeaterRepeater 控件添加事件 onitemdatabound="RepeaterArticleList_ItemDataBound" 接下来是完成代码
protected void RepeaterArticleList_ItemDataBound(object sender, RepeaterItemEventArgs e) { DropDownList drd = (DropDownList)e.Item.FindControl("droplist1"); HiddenField hid = (HiddenField)(e.Item.FindControl("HiddenField1")); //用你的方法通过ID得到状态值到userstate string userstate = getUserStateByID(hid.Value); drd.SelectedValue = userstate ; } |
Repeater 实现 OnSelectedIndexChanged的更多相关文章
- UpdatePanel里的Repeater和DropDownList
在updatepanel里使用dropdownlist的AutoPostBack,正常情况下都可以局部刷新. 但是,如果updatepanel下是Repeater,repeater里绑定dropdow ...
- 在Repeater中使用DropDownList的方法
在Repeater中使用DropDownList的方法 以下代码并不完整,只记录了关键的方法 aspx代码中 假设这是一个用户管理的系统的模型,有一个下拉菜单来操作用户状态 <asp:Repea ...
- 使用Repeater控件实现三层嵌套以及分页效果
PS: 第一次用Repeater控件 记录一下 请忽略我的命名不规范 请忽略我的最终效果图(太丑了) 需要用到的朋友可以自行调整的漂亮点 ====================最终效果图===== ...
- repeater列表中直接修改状态
<asp:Repeater ID="RepeaterArticleList" runat="server" onitemdatabound="R ...
- C# 在Repeater 的ItemDataBound 如何转换e.Item.DataItem 的类型
1.使用DataSet和DataTable绑定数据源时,用 DataRowView view = (DataRowView)e.Item.DataItem; 2.DataReader绑定数据源时,用 ...
- Webform(七)——内置对象(Session、Application)和Repeater的Command操作
内置对象:用于页面之间的数据交互 为什么要使用这么内置对象?因为HTTP的无状态性. 一.内置对象 (一)Session 跟Cookies一样用来存储用户数据 1.Session.Cookies对比 ...
- Webform(五)——内置对象(Response、Request)和Repeater中的数据增删改
一.内置对象 (一)Response对象 1.简介:response 对象在ASP中负责将信息传递给用户.Response对象用于动态响应客户端请求,并将动态生成的响应结果返回到客户端浏览器中,使用R ...
- webform Repeater重复器、地址栏传值、Response
Repeater: 重复器 <HeaderTemplate></HeaderTemplate> - 头模板:在循环开始时,其内容只会打印一遍 <ItemTemplate& ...
- Repeater、地址栏传值、Response--2016年12月30日
Repeater Repeater支持以下5种模板 ● ItemTemplate : 对每一个数据项进行格式设置 [Formats each item from the data sou ...
随机推荐
- 利用BootStrap Table插件实现自己的弹出框分页。
参考链接1: 官网:http://bootstrap-table.wenzhixin.net.cn/zh-cn/home/ 开始使用:http://bootstrap-table. ...
- ssh-copy-id Permission denied (publickey,gssapi-keyex,gssapi-with-mic). 的解决方案
-bash-4.2# ssh-copy-id 192.168.9.180 /usr/bin/ssh-copy-id: INFO: attempting to log in with the new k ...
- Selenium断言的使用,等待
自动化测试常用断言的使用方法(python) 自动化测试中寻找元素并进行操作,如果在元素好找的情况下,相信大家都可以较熟练地编写用例脚本了,但光进行操作可能还不够,有时候也需要对预期结果进行判断. 这 ...
- 格式时间转UTC时间
public void dateChange() throws ParseException { String str="2010-5-27 12:10:12"; SimpleDa ...
- linux操作笔记记录
export https_proxy=https://10.10.2.91:8888export http_proxy=http://10.10.2.91:8888 桥接模式:需要配一个静态ip,可以 ...
- Android的Service组件
首先,Service在Android体系中是什么?有什么功能?1. Service是服务,其执行线程是UI主线程(宿主进程的主线程):2. 和Activity最大的不同是:Service不涉及到与用户 ...
- XV Open Cup named after E.V. Pankratiev. GP of America
A. Area of Effect 首先最优解中必有一个点在圆的边界上. 若半径就是$R$,则枚举一个点,然后把剩下的事件极角扫描即可,时间复杂度$O(m(n+m)\log(n+m))$. 否则圆必然 ...
- Spring 使用 feign时设置header信息
最近使用 SpringBoot 项目,把一些 http 请求转为 使用 feign方式.但是遇到一个问题:个别请求是要设置header的. 于是,查看官方文档和博客,大致推荐两种方式.也可能是我没看明 ...
- vue_小项目_吃饭睡觉打豆豆
vue_小项目_吃饭睡觉打豆豆 onmouseenter 和 onmouseleave : 在 移入/移出 子元素时不会重复触发 onmouseover 和 onmouseout : 在 移入/移出 ...
- Android常用的工具类SharedPreferences封装类SPUtils
package com.zhy.utils; import java.lang.reflect.InvocationTargetException; import java.lang.reflect. ...