在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 ; 
   
    

转自https://www.cnblogs.com/zdkjob/articles/2256917.html

Repeater 实现 OnSelectedIndexChanged的更多相关文章

  1. UpdatePanel里的Repeater和DropDownList

    在updatepanel里使用dropdownlist的AutoPostBack,正常情况下都可以局部刷新. 但是,如果updatepanel下是Repeater,repeater里绑定dropdow ...

  2. 在Repeater中使用DropDownList的方法

    在Repeater中使用DropDownList的方法 以下代码并不完整,只记录了关键的方法 aspx代码中 假设这是一个用户管理的系统的模型,有一个下拉菜单来操作用户状态 <asp:Repea ...

  3. 使用Repeater控件实现三层嵌套以及分页效果

    PS: 第一次用Repeater控件 记录一下 请忽略我的命名不规范  请忽略我的最终效果图(太丑了) 需要用到的朋友可以自行调整的漂亮点 ====================最终效果图===== ...

  4. repeater列表中直接修改状态

    <asp:Repeater ID="RepeaterArticleList" runat="server" onitemdatabound="R ...

  5. C# 在Repeater 的ItemDataBound 如何转换e.Item.DataItem 的类型

    1.使用DataSet和DataTable绑定数据源时,用 DataRowView view = (DataRowView)e.Item.DataItem; 2.DataReader绑定数据源时,用 ...

  6. Webform(七)——内置对象(Session、Application)和Repeater的Command操作

    内置对象:用于页面之间的数据交互 为什么要使用这么内置对象?因为HTTP的无状态性. 一.内置对象 (一)Session 跟Cookies一样用来存储用户数据 1.Session.Cookies对比 ...

  7. Webform(五)——内置对象(Response、Request)和Repeater中的数据增删改

    一.内置对象 (一)Response对象 1.简介:response 对象在ASP中负责将信息传递给用户.Response对象用于动态响应客户端请求,并将动态生成的响应结果返回到客户端浏览器中,使用R ...

  8. webform Repeater重复器、地址栏传值、Response

    Repeater: 重复器 <HeaderTemplate></HeaderTemplate> - 头模板:在循环开始时,其内容只会打印一遍 <ItemTemplate& ...

  9. Repeater、地址栏传值、Response--2016年12月30日

    Repeater  Repeater支持以下5种模板       ● ItemTemplate : 对每一个数据项进行格式设置 [Formats each item from the data sou ...

随机推荐

  1. SpringBoot配置分析、获取到SpringBoot配置文件信息以及几种获取配置文件信息的方式

    Spring入门篇:https://www.cnblogs.com/biehongli/p/10170241.html SpringBoot的默认的配置文件application.properties ...

  2. Spring Boot 读取 resource 下文件

    支持linux下读取 import org.springframework.core.io.ClassPathResource; public byte[] getCertStream(String ...

  3. SQL反模式学习笔记13 使用索引

    目标:优化性能 改善性能最好的技术就是在数据库中合理地使用索引.  索引也是数据结构,它能使数据库将指定列中的某个值快速定位在相应的行. 反模式:无规划的使用索引 1.不使用索引或索引不足 2.使用了 ...

  4. SQL反模式学习笔记22 伪键洁癖,整理数据

    目标:整理数据,使不连续的主键Id数据记录变的连续. 反模式:填充断档的数据空缺. 1.不按照顺序分配编号 在插入新行时,通过遍历表,找到的第一个未分配的主键编号分配给新行,来代替原来自动分配的伪主键 ...

  5. 修改pip安装源加快python模块安装

    用pip安装依赖包时默认访问https://pypi.python.org/simple/,但是经常出现不稳定以及访问速度非常慢的情况,国内厂商提供的pipy镜像目前可用的有: http://pypi ...

  6. Prime Distance POJ - 2689 (数学 素数)

    The branch of mathematics called number theory is about properties of numbers. One of the areas that ...

  7. day10_friest_自动化

    一.知识回顾, 1.构造函数:def __del__(self)是类执行完后,需要将某些如连接等关闭,可将关闭代码写在该函数中,既是实例被销毁的时候执行 2.私有寒素:def __say(self)表 ...

  8. angular.isNumber()

    <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...

  9. 九、JSP入门(1)

    JSP入门 1 JSP概述 1.1 什么是JSP JSP(Java Server Pages)是JavaWeb服务器端的动态资源.它与html页面的作用是相同的,显示数据和获取数据. 1.2 JSP的 ...

  10. python语法_元组

    tuple 元组 被称为只读列表 tup = (1,3,4,'234') 只能读,不能进行修改操作. 与列表的区分就是 () [] 中括号和小括号的区别,