<script type= "Text/javascript" >//with "Select All" check box as parameter function Checkall () {var checkall = Document.getelement Byid ("All"); var Checkitem = document.getelementsbytagname ("input"); for (var i = 0; i < checkitem.length; i++) {if (checkitem[i].type== "checkbox") {Checkitem[i]. checked = checkall.checked; }}}//Gets the selected check box 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 code:
<input type= "checkbox" id= "All" onclick= "Checkall ()"/> Select all <input type= "checkbox" Name= "Item" value= "<%# Eval ("Id")%> "/>
<input type= "hidden" id= "Hidbookid" name= "Hidbookid" runat= "Server"/> The selected books are categorized in: <asp:d Ropdownlist id= "ddlcategory" runat= "Server" ></asp:DropDownList> <asp:button id= "Btncategory" runat = "Server" text= "Modify " onclick= "Btncategory_click" onclientclick= "Update ();"/>
Background code:
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{Prote CTED void Page_Load (object sender, EventArgs e) {if (! IsPostBack) {categorybind (); Booksbind (); }}///<summary>//Binding Data///</summary>//<param name= "PM" ></param> PR otected void Booksbind () {list<book> List = new Bookmanager (). Getallbooks (); This.gvBooks.DataSource = list; This.gvBooks.DataBind (); }///<summary>//binding book type name///</summary> protected void Categorybind () {this.ddlcate Gory. DataSource = new Categorymanager (). Getallcategory (); This.ddlCategory.DataTextField = "Name"; This.ddlCategory.DataValueField = "Id"; This.ddlCategory.DataBind (); } protectedvoid Gvbooks_pageindexchanging (object sender, Gridviewpageeventargs e) {//Get index number This.gvBooks.PageIndex = E.newpageindex; Booksbind (); }///<summary>///Click Modify button Events///</summary>//<param name= "sender" ></param>/// Lt;param name= "E" ></param> protected void Btncategory_click (object sender, EventArgs e) {str ing 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 (); }}
. NET background fetch JS assigned value to Hidden