您的位置:首页 > 其它

关于GridView

2016-03-21 10:43 183 查看
//—————————————————新增总结————————————————————

1.GridView的多选效果(注意一个字都不要错才能运行)

(1)先在JavaScript中写代码:

<head runat="server">

<script language="javascript">

    function
GetAllCheckBox(CheckAll)

   {

       
var items=document.getElementsByTagName_r("input");

       
for(i=0;i<items.length;i++)

       
{

           
if(items[i].type=="checkbox")

           
{

               
items[i].checked=CheckAll.checked;                

           
}

       
}

   }

</script>

   
<title>无标题页</title>

(2)在控件的onclick事件中写代码(即使控件没有这个事件,也要硬写上去)

<asp:CheckBox ID="chkCheckAll" runat="server"
Text="全选"
onclick="javascript:GetAllCheckBox(this)"/>

 

2.GridView的光棒效果:——要在它的行绑定事件中写:里面注释的即是。

 //GridView的行绑定事件

    protected
void GridView1_RowDataBound(object sender, GridViewRowEventArgs
e)

    {

       
if (e.Row.RowType == DataControlRowType.DataRow)

       
{

         

           
if (e.Row.RowState == DataControlRowState.Normal || e.Row.RowState
== DataControlRowState.Alternate)

           
{

               
//关于多选框

               
CheckBox box =
(CheckBox)e.Row.Cells[7].FindControl("CboxSelect");

               
if (MessageManager.IDList != null)

               
{

                   
if (MessageManager.IDList.Contains( box.Text))

                   
{

                       
box.Checked = true;  

                   
}

               
}

             
//为GridView添加光棒效果

               
e.Row.Attributes.Add("onmouseover",
"currentcolor=this.style.backgroundColor;this.style.backgroundColor='#6699ff'");

               
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: