在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,执行操作

  1. 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);
  2.  
  3. //已经拿到了id,可以进行操作
  4.  
  5. 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. 华为交换机批量加入 Vlan 方法

    华为交换机单独加入vlan太麻烦,思科有批量加入vlan的方法,华为也有.要求 1~6口划分到vlan2,6~12口划分到vlan3,13~18口划分到vlan4,19~24口划分到vlan5.25, ...

  2. ansible的tests

    Ansible的tests : 路径 /usr/lib/python2.7/site-packages/ansible/plugins/test core.py # failure testing ' ...

  3. 【转】Oracle imp 总是不停地重复闪烁

    http://blog.itpub.net/7282477/viewspace-1003160/ 在dos下执行: imp username/password buffer=1000000 file= ...

  4. mysql的坑

    mysql安装报错: 1.The service already exists! The current server installed: 因为mysql卸载不完全. 解决方法: C:\window ...

  5. day26 面向对象 单例模式总结

    如果是在python2中,就需要手动继承object, 基于__new__方法 基于__new__方法 class Foo(object): def __new__(cls,*args,**kwarg ...

  6. 横向滑动的listview和其中用到的触摸监听事件详解

    一.首先把横向的listview的代码放上来 HorizontalListView: package com.common.cklibrary.utils.myview; import java.ut ...

  7. sys.stdout = io.TextIOWrapper(sys.stdout.buffer,encoding='utf8') #改变标准输出的默认编码

    不论使用urllib还是使用requests库经常会遇到中文编码错误的问题,我就经常遇到,因为python安装在windows平台上,cmd的默认编码为GBK,所以在cmd中显示中文时会经常提示gbk ...

  8. nginx 配置laravel框架域名配置

    server { listen 80; server_name admin.meiquick.local.com; #charset koi8-r; # access_log /var/log/ngi ...

  9. 消息队列——ActiceMQ

    1.下载apache-activemq-5.xx.x,\bin\win64目录下运行activemq.bat.之后可进入管理员界面http://localhost:8161/admin,账号密码均为a ...

  10. 2018.我的NOIP补全计划

    code: efzoi.tk @ shleodai noip2011 D1 选择客栈 这道题是一道大水题,冷静分析一会就会发现我们需要维护最后一个不合法点和前缀和. 维护最后一个不合法点只要边扫描边维 ...