问题描述
在gridview里面选HeaderTemplate里的checkbox后,全选ItemTemplate里的checkbox,如何实现选中行颜色的变化,要用js实现,(在后台我已经实现了,要刷新页面不是很喜欢)
解决方案
解决方案二:
你可以用ajax.net的updatepanel控件实现局部刷新,也可以用JS获取相应Form中的checkbox控件,然后操作相应样式。
解决方案三:
帮顶
解决方案四:
<%@PageLanguage="C#"AutoEventWireup="true"CodeFile="gv3.aspx.cs"Inherits="gv3"%><!DOCTYPEhtmlPUBLIC"-//W3C//DTDXHTML1.0Transitional//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><htmlxmlns="http://www.w3.org/1999/xhtml"><headrunat="server"><title>无标题页</title><scriptlanguage="javascript"type="text/javascript">functiona(obj){//alert("进入方法");if(obj.checked){obj.parentNode.parentNode.style.backgroundColor='blue';}else{obj.parentNode.parentNode.style.backgroundColor='';}}</script></head><body><formid="form1"runat="server"><div><asp:GridViewID="GridView1"runat="server"><Columns><asp:TemplateField><ItemTemplate><inputid='Checkbox_<%#Eval("ID")%>'type="checkbox"onclick="a(this);"/></ItemTemplate></asp:TemplateField></Columns></asp:GridView><inputid="Checkbox1"checked="checked"type="checkbox"/></div></form></body></html>
解决方案五:
我上面实现的是单个点击,如果是全选的话应该也差不多
解决方案六:
<%@PageLanguage="C#"AutoEventWireup="true"CodeFile="ShowNews.aspx.cs"Inherits="ShowNews"%><%@RegisterSrc="WebUserControl.ascx"TagName="WebUserControl"TagPrefix="uc1"%><!DOCTYPEhtmlPUBLIC"-//W3C//DTDXHTML1.0Transitional//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><htmlxmlns="http://www.w3.org/1999/xhtml"><headrunat="server"><title>新闻管理</title><scripttype="text/javascript">functionSelectAll(tempControl){vartheBox=tempControl;xState=theBox.checked;elem=theBox.form.elements;for(i=0;i<elem.length;i++){if(elem[i].type=="checkbox"&&elem[i].id!=theBox.id){if(elem[i].checked!=xState){elem[i].click();}}}}functionchangecolor(cbo,o){vartheBox=cbo;vartr=document.getElementById(o);if(theBox.checked){tr.style.backgroundColor="Red";}else{tr.style.backgroundColor="#CCCCCC";}}</script></head><body><formid="form1"runat="server"><div><tableborder="1"cellspacing="0"cellpadding="0"style="width:800px"align="center"><tr><td> <uc1:WebUserControlID="WebUserControl1"runat="server"/></td></tr><tr><tdstyle="height:154px"><asp:GridViewID="GridUsers"runat="server"AutoGenerateColumns="False"DataKeyNames="NewId"Width="795px"OnRowDeleting="GridUsers_RowDeleting"OnRowDataBound="GridUsers_RowDataBound"><Columns><asp:HyperLinkFieldDataNavigateUrlFields="NewId"DataNavigateUrlFormatString="UpdataNews.aspx?NewId={0}"DataTextField="NewTitle"HeaderText="新闻标题"/><asp:BoundFieldDataField="NewText"HeaderText="内容"/><asp:BoundFieldDataField="NewTime"HeaderText="发布时间"SortExpression="UserName"><ControlStyleWidth="100px"/></asp:BoundField><asp:BoundFieldDataField="UserLogin"HeaderText="发布人"SortExpression="UserPwd"><ControlStyleWidth="100px"/></asp:BoundField><asp:TemplateFieldShowHeader="False"><ItemTemplate><asp:LinkButtonID="LinkButton1"runat="server"CausesValidation="False"CommandName="Delete"OnClientClick="returnconfirm('你确定要删除此项吗?');"Text="删除"></asp:LinkButton></ItemTemplate></asp:TemplateField><asp:TemplateField><HeaderTemplate><asp:CheckBoxID="CheckAll"runat="server"Text="全选"onclick="javascript:SelectAll(this);"/></HeaderTemplate><ItemTemplate><asp:CheckBoxID="CheckSingle"runat="server"/></ItemTemplate></asp:TemplateField></Columns></asp:GridView> <tableborder="0"cellpadding="0"cellspacing="0"><tr><tdstyle="width:1712px;height:19px"></td><tdstyle="width:100px;height:19px"></td></tr></table></td></tr></table></div></form></body></html>
参考这个。。。颜色你可以改你自己喜欢的。
解决方案七:
functionUpDomAll(changeBox){vargridView=document.getElementById("GridView1");//这里放指定的GridView的ID,可以从changeBox分析得出vartbodyNode=gridView.childNodes[0];for(vari=1;i<tbodyNode.childNodes.length;i++){varrowBox=tbodyNode.childNodes[i].childNodes[0].firstChild.lastChild;if(rowBox.checked!=changeBox.checked&&!rowBox.disabled){rowBox.checked=changeBox.checked;UpDom(tbodyNode.childNodes[i].childNodes[0].firstChild);}}}应该和这个差不多
解决方案八:
没用啊!全选可以的,但是不能改变颜色啊
解决方案九:
<%@PageLanguage="C#"AutoEventWireup="true"CodeFile="test.aspx.cs"Inherits="test"%><!DOCTYPEhtmlPUBLIC"-//W3C//DTDXHTML1.0Transitional//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><htmlxmlns="http://www.w3.org/1999/xhtml"><headrunat="server"><title>无标题页</title><scriptlanguage="javascript"type="text/javascript">functionselectAll(obj){//varelem=document.getElementById('GridView1').getElementsByTagName('INPUT');varelem=document.getElementById('<%=GridView1.ClientID%>').getElementsByTagName('INPUT');//varelem=obj.parentNode.parentNode.parentNode.getElementsByTagName('INPUT');for(i=0;i<elem.length;i++){if(elem[i].type=="checkbox"&&elem[i].id!='cbkALL'){elem[i].checked=obj.checked;if(obj.checked){elem[i].parentNode.parentNode.style.backgroundColor='red';}else{elem[i].parentNode.parentNode.style.backgroundColor='';}}}}functionchangeColor(obj){if(obj.checked)obj.parentNode.parentNode.style.backgroundColor='red';elseobj.parentNode.parentNode.style.backgroundColor='';}</script></head><body><formid="form1"runat="server"><div><asp:GridViewID="GridView1"runat="server"><Columns><asp:TemplateField><HeaderTemplate><inputtype="checkbox"id='ckbALL'onclick="selectAll(this);"/></HeaderTemplate><ItemTemplate><inputtype="checkbox"name="ckb"onclick="changeColor(this);"/><asp:ButtonID="btn"runat="server"Text="ok"/></ItemTemplate></asp:TemplateField></Columns></asp:GridView></div></form></body></html>
usingSystem;usingSystem.Data;usingSystem.Configuration;usingSystem.Collections;usingSystem.Web;usingSystem.Web.Security;usingSystem.Web.UI;usingSystem.Web.UI.WebControls;usingSystem.Web.UI.WebControls.WebParts;usingSystem.Web.UI.HtmlControls;publicpartialclasstest:System.Web.UI.Page{protectedDataTablegetDataTable(){System.Data.DataTabledt=newSystem.Data.DataTable();System.Data.DataRowdr;dt.Columns.Add(newSystem.Data.DataColumn("ID",typeof(System.Int32)));dt.Columns.Add(newSystem.Data.DataColumn("Name",typeof(System.String)));dr=dt.NewRow();dr[0]=1;dr[1]="小明";dt.Rows.Add(dr);dr=dt.NewRow();dr[0]=2;dr[1]="小强";dt.Rows.Add(dr);dr=dt.NewRow();dr[0]=3;dr[1]="小张";dt.Rows.Add(dr);dr=dt.NewRow();dr[0]=4;dr[1]="小李";dt.Rows.Add(dr);dr=dt.NewRow();dr[0]=5;dr[1]="小关";dt.Rows.Add(dr);returndt;}protectedvoidPage_Load(objectsender,EventArgse){GridView1.DataSource=getDataTable();GridView1.DataBind();}}
解决方案十:
学习了