zoukankan      html  css  js  c++  java
  • Repeater中绑定DropDownList和使用RepeaterItem

    还是正在做的项目中遇到了使用Rpt的问题。查过MSDN后得到解决。

    以前的后台系统用到了大量的GridView,前台都是Repeater。现在后台也用Repeater了~

    代码如下:

    ASPX:

           <asp:UpdatePanel ID="UpDPanelRptNews" runat="server" ChildrenAsTriggers="true" UpdateMode="Always">

              <ContentTemplate>

                <asp:Repeater ID="RptNew" runat="server" onitemdatabound="RptNew_ItemDataBound">

                <HeaderTemplate>

                    <table border="0" align="center" cellpadding="1" cellspacing="1" width="580px" class="UserTable">

                      <tr class="UserTableRow2"><td width="150px"><b>标题</b></td><td width="80px"><b>作者</b></td><td width="75px"><b>类型</b></td><td width="75px"><b>是否显示</b></td><td width="100px"><b>删除</b></td></tr>     

                </HeaderTemplate>

                <ItemTemplate>

                   <tr onmouseover="c=this.style.backgroundColor;this.style.backgroundColor='#00A9FF'" onmouseout="this.style.backgroundColor=c"><td width="150px"><a href='Admin_News.aspx?id=<%# Eval("id") %>' title='<%# Eval("title")+"["+Eval("adddate")+"}" %>'><%# WebFunction.StrHelper.CutStringMit(Eval("title").ToString(),20) %></a></td><td width="80px"><%# Eval("addname") %></td><td width="75px"><%# Eval("flag").ToString()=="1"?"动态":"新闻" %></td>

                   <td width="75px">

                   <asp:DropDownList ID="DListNewsIsShow" runat="server" AutoPostBack="true" OnSelectedIndexChanged="DListNewsIsShow_SelectedIndexChanged">

                      <asp:ListItem Value="1"></asp:ListItem>

                      <asp:ListItem Value="0"></asp:ListItem>

                   </asp:DropDownList><asp:Label ID="LabId" runat="server" Visible="false" Text='<%# Eval("id") %>'></asp:Label>

                   </td>

                </ItemTemplate>

                <FooterTemplate></table></FooterTemplate>

                </asp:Repeater>

               </ContentTemplate>

             </asp:UpdatePanel> 

    CS:

            //遍历RptDListNewsIsShow的数据读取

            protected void RptNew_ItemDataBound(object sender, RepeaterItemEventArgs e)

            {

                if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem || e.Item.ItemType == ListItemType.SelectedItem)

                {

                    DataRowView rowv = (DataRowView)e.Item.DataItem;

                    DropDownList DListNewsIsShow = (DropDownList)e.Item.FindControl("DListNewsIsShow");

                    DListNewsIsShow.Items.FindByValue(rowv["isshow"].ToString()).Selected = true;

                }

            }

                   

            //异步更新新闻是否显示

            protected void DListNewsIsShow_SelectedIndexChanged(object sender, EventArgs e)

            {

                DropDownList DListFNewsIsShow = sender as DropDownList;

                RepeaterItem item = DListFNewsIsShow.Parent as RepeaterItem; //转为所在Item

                Label LabFId = item.FindControl("LabId") as Label;  //查找

                NewsInfo newsInfoRpt = new NewsInfo();

                newsInfoRpt.Id = LabFId.Text.ToString();

                newsInfoRpt.IsShow = Convert.ToInt16(DListFNewsIsShow.SelectedValue.ToString());

                if(news.Update(newsInfoRpt,"1")<=0)

                {

                    ScriptManager.RegisterStartupScript(UpDPanelRptNews, typeof(UpdatePanel), "JsAlert", "alert('对不起,更新失败!!')", true);

                }

            }

  • 相关阅读:
    弹窗拖拽组件开发应用
    高级事件的运用
    常见排序算法(JS版)
    原生js实现仿window10系统日历效果
    原生js实现吸顶导航和回到顶部特效
    OVN实战---《The OVN Gateway Router》翻译
    OVN实战---《An Introduction to OVN Routing》翻译
    OVN实战---《A Primer on OVN》翻译
    深入理解CNI
    《CNI specification》翻译
  • 原文地址:https://www.cnblogs.com/astar/p/1289505.html
Copyright © 2011-2022 走看看