• .net 后台取js赋给hidden的值


     <script type="text/javascript">
        //以“全选”复选框作为参数
        function checkAll(){
            var checkAll = document.getElementById("All");
            var checkItem = document.getElementsByTagName("input");
            for (var i = 0; i < checkItem.length; i++) {
                if(checkItem[i].type=="checkbox"){
                    checkItem[i].checked = checkAll.checked;
                }
            }
        }
    
        //获取选中的复选框
        function Update() {       
             var chkItems = document.getElementsByName("Item");
                var bookId = "";           
                for (var i = 0; i < chkItems.length; i++) {              
                    if (chkItems[i].checked) {
                        bookId += chkItems[i].value + ",";
                    }
                }           
                bookId = bookId.substr(0, bookId.length - 1);          
                document.getElementById('<%=hidBookId.ClientID%>').value = bookId;
                    //alert(document.getElementById('<%=hidBookId.ClientID%>').value);
            }
    </script>
    

       

    HTML代码:

    <input type="checkbox" id="All" onclick="checkAll()"/>全选
    <input type="checkbox" name="Item" value="<%# Eval("Id") %>" />
    
      <input type="hidden" id="hidBookId"  name="hidBookId" runat="server" />  
        将选中的书籍归类于:<asp:DropDownList ID="ddlCategory" runat="server"></asp:DropDownList>
      <asp:Button ID="btnCategory" runat="server" Text="修  改" OnClick="btnCategory_Click"  OnClientClick="Update();" />
    

     

    后台代码: 

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using Model;
    using BLL;
    public partial class ListBooksByCategory : System.Web.UI.Page
    {
       
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                CategoryBind();
                BooksBind();        
            }      
        }
    
        /// <summary>
        /// 绑定数据
        /// </summary>
        /// <param name="pm"></param>
        protected void BooksBind()
        {
            List<Book> list = new BookManager().GetAllBooks();
            this.gvBooks.DataSource = list;
            this.gvBooks.DataBind();
        }
    
        /// <summary>
        /// 绑定图书类型名称
        /// </summary>
        protected void CategoryBind()
        {
            this.ddlCategory.DataSource = new CategoryManager().GetAllCategory();
            this.ddlCategory.DataTextField = "Name";
            this.ddlCategory.DataValueField = "Id";
            this.ddlCategory.DataBind();
        }
    
        protected void gvBooks_PageIndexChanging(object sender, GridViewPageEventArgs e)
        {
            //获取索引编号
            this.gvBooks.PageIndex = e.NewPageIndex;
            BooksBind();
        }
    
        /// <summary>
        /// 单击修改按钮事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void btnCategory_Click(object sender, EventArgs e)
        {        
           string strBookId = this.hidBookId.Value;
           string[] array = strBookId.Split(',');
           for (int i = 0; i < array.Count(); i++)
           {
               int categoryId = Convert.ToInt32(this.ddlCategory.SelectedValue);
               new BookManager().UpdateCategoryIdById(Convert.ToInt32(array[i]), categoryId);
           }      
           BooksBind();
        }
    }
    

      

  • 相关阅读:
    为什么switch里的case没有break不行
    CLS的探索:Python如何让日志免费云化
    做一次“黑客“,入侵一次自己的服务器
    斥资288买了三年服务器之后应该如何配置
    Scrapy入门到放弃01:开启爬虫2.0时代
    c#自制抽奖小程序
    c#中的几种Dialog
    解决数据库排序空值排在前问题
    Oracle 数据库添加定时事件
    FileReader 对象实现图片预览
  • 原文地址:https://www.cnblogs.com/chk520/p/4458204.html
Copyright © 2020-2023  润新知