为了账号安全,请及时绑定邮箱和手机立即绑定

下拉框实现下拉数据改变动态更新数据

下拉框实现下拉数据改变动态更新数据

吃鸡游戏 2018-09-12 05:02:41
大哥们 帮我看看这个小问题 呀  repeart控件,前面是个下拉框的input的select标签,怎么实现下拉框中的值更换了之后 后面数据也跟着变化呀
查看完整描述

2 回答

?
千万里不及你

TA贡献1784条经验 获得超9个赞

直接贴代码了:

            <ItemTemplate>
               <tr >
               <td>
               <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>

...

        //遍历Rpt中DListNewsIsShow的数据读取
        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);
            }
        }


查看完整回答
反对 回复 2018-09-16
  • 2 回答
  • 0 关注
  • 1602 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信