zoukankan      html  css  js  c++  java
  • Repeater下拉事件触发修改本行数据

          几行代码搞定,太漂亮了,记录总结下。  前台代码如下

    <asp:Repeater ID="Repeater2" OnItemDataBound="Repeater2_OnItemDataBound" runat="server">
                                                    <ItemTemplate>
                                                        <tr runat="server" id="row">
     <td style="text-align: center">
                                                                
                                                             <asp:DropDownList ID="ddlTFDate" Enabled="true" AutoPostBack="true" OnSelectedIndexChanged="ddlTFDate_TextChanged" runat="server">  
                                                                    <asp:ListItem Value="否">否</asp:ListItem>  
                                                                    <asp:ListItem Value="是">是</asp:ListItem>
                                                 
                                                                </asp:DropDownList>
                                                            
                                                            </td>
                                                            <td style="text-align: center">
    
                                                                 <asp:TextBox ID="txtQJC12" Text='<%#  Eval("QJC12")%>' runat="server" Width="80px"></asp:TextBox>
    
                                                            </td>
      </tr>
                                                    </ItemTemplate>
                                                </asp:Repeater>
    

     后台代码如下:

     protected void ddlTFDate_TextChanged(object sender, EventArgs e)
        {
            DropDownList ddl1 = ((DropDownList)sender).Parent.FindControl("ddlTFDate") as DropDownList;
            TextBox txt1 = ((DropDownList)sender).Parent.FindControl("txtQJC12") as TextBox;
            if (ddl1.SelectedItem.Text.Equals("是"))
            {
               txt1.Text = DateTime.Now.ToString("yyyy-MM-dd");
            }
            else
            {
                txt1.Text = "";
            }       
             // 经过测试  CheckBox  无法获取到   直接  CheckBox 事件下 可以获取到 CheckBox cb_choose = (CheckBox)sender;
            RepeaterItem item =ddl1.NamingContainer as RepeaterItem;
            Repeater grd = item.NamingContainer as Repeater;
            CheckBox cb = item.FindControl("cbXJA16") as CheckBox;
                
          }
    

     数据下拉加载绑定

    protected void Repeater2_OnItemDataBound(object sender, RepeaterItemEventArgs e)
        {
            if (e.Item.ItemType.Equals(ListItemType.Item) || e.Item.ItemType.Equals(ListItemType.AlternatingItem))
            {
                DropDownList ddl = (DropDownList)e.Item.FindControl("ddlTFDate");
    
                ListItem li = ddl.Items.FindByText(DataBinder.Eval(e.Item.DataItem, "QJC11").ToString().Trim());
                if(li!=null)
                {
                    ddl.ClearSelection();
                    li.Selected = true;
                }
    
                //ddl.SelectedItem.Value = DataBinder.Eval(e.Item.DataItem, "QJC11").ToString().Trim();
            }
        }
    

      

    你的一分支持,是我坚持创作的十分动力。 如果文章的内容对你有帮助的话,请用微信扫描下方二维码,支持一下。谢谢! wechat1
  • 相关阅读:
    doraemon的python 从计算机基础到面向对象的笔记(加面试题)
    doraemon的python 单例模式和日志操作(我的笔记整合起来就是一份完成的python学习资料)
    Mybatis系列教材 (十七)- 相关概念
    Mybatis系列教材 (十六)- 注解
    Mybatis系列教材 (十五)- 注解
    Mybatis系列教材 (十四)- 注解
    Mybatis系列教材 (十三)- 注解
    Mybatis系列教材 (十二)- 注解
    Mybatis系列教材 (十一)- 动态SQL
    Mybatis系列教材 (十)- 动态SQL
  • 原文地址:https://www.cnblogs.com/shuilong/p/11597752.html
Copyright © 2011-2022 走看看