In many cases, we need a "Select All" feature when managing or viewing a list, which is very easy to implement in ASP. I'll show you a little bit of code to do that.
To achieve a full selection or a small function of JS:
function Checkall (e,itemname) {
var aa=document.getelementsbyname (itemname);
if (aa==undefined) return;
for (var i=0; i<aa.length; i++) aa[i].checked = e.checked;
}
First look at the implementation process in the Asp:repeater.
Add a checkbox that is selected directly in HeaderTemplate:
<input name= "Chkall" value= "1" type= "checkbox" onclick= "Checkall (This, ' Item ')"/>
When binding in ItemTemplate, you only need to set the ID number of the current row to input:
<TD align= "center" ><input name= "Item" type= "checkbox" Value= ' <%# Eval ("deal_id")%> '/></td>
Then we create a "delete all" LinkButton, which executes a background code when clicked:
<asp:linkbutton id= "Lb_bak_delete" text= "bulk Delete" oncommand= "Linkbutton_command" runat= "server" commandname= "delete "visible=" false "/>
The function name that is executed is Linkbutton_command, and the main purpose of setting the parameter commandname is to mark this operation as delete function (many times also need to generate AH, highlight AH and so on), to see the execution of Linkbutton_command:
protected void Linkbutton_command (Object sender, CommandEventArgs e) {
String ids=request.form["Item"];
Switch (e.commandname) {
Case "Delete":
Bakdelete (IDS);
Break
}
Data_list_load ();//Reload
return;
}
private void Bakdelete (string IDs) {
Odeal is a class
if (! String.IsNullOrEmpty (IDs) && odeal.delete ("[deal_id] In (" +ids+ ")") {
Outmess ("Bulk Delete data success");
}else{
Outmess ("bulk Delete failed");
}
}
Then let's look at the method in the DataGrid or DataView:
The use of JS is the same, when displayed in the foreground:
<asp:templatecolumn headertext= "<input name= ' Chkall ' value= ' 1 ' type= ' checkbox ' onclick= ' Checkall (this,JS_Item _text) '/> ' itemstyle-width= "30px" itemstyle-horizontalalign= "center" headerstyle-horizontalalign= "center" headerstyle-cssclass= "Head" >
<itemtemplate><input name= "Item" type= "checkbox" Value= ' <%# Eval ("td_id")%> '/></itemtemplate >
</asp:TemplateColumn>
It should be noted here that Checkall executes a single quotation mark in the method, here is not added, the first declaration of a JS variable, and then in the loading list of the time to write a JS client registration:
When the list is Classgriddatabind, add:
String sscript = "var js_item_text= ' Item ';";
ClientScriptManager OBJCSM = Page.clientscript;
if (! Objcsm.isstartupscriptregistered ("_js_item_text")) {
Objcsm.registerstartupscript (this. GetType (), "_js_item_text", Sscript, True);
}
Then the rest and the repeater are the same.
This article from Csdn Blog, reproduced please indicate the source: http://blog.csdn.net/xielingxu/archive/2008/07/28/2726089.aspx
Category: ASP.
Asp. NET to Datagrid,repeater, such as the addition of the full selection of bulk delete functions (GO)