e.Row.Attributes.Add

其实看到属性这个单词,还有点发憷呢,C#里面有个关键词是Attributes, 搞了半天貌似没有弄清楚

e.Row.Attributes.Add()函数的介绍,包括参数,什么是Attributes

就是往行里面添加属性
相当于html里面的一个表里的一个行的属性,你看看那个属性有什么,这个就可以添加什么属性
//这个就是在前台添加一个Button的按钮,然后给他添加事件
   <asp:Button ID="Button1" runat="server" Text="Button" />
 //为Button1添加onclick()事件 ,Button为服务器控件
  Button1.Attributes.Add("onclick", "return checkSame()");
<head>
 <title></title>
    <script type="text/javascript" >
        function checkSame()
        {
            var d = document.getElementById("las");
            alert(456789)
            //d.innerText = 456;
            return 5;
        }
        document.getElementById("las45").innerHTML = checkSame();
    </script>
</head> 

  


一般用到的最多的是什么鼠标移入和移除

protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e) { int i; //执行循环,保证每条数据都可以更新 for (i = 0; i < GridView1.Rows.Count; i++) { //首先判断是否是数据行 if (e.Row.RowType == DataControlRowType.DataRow) { //当鼠标停留时更改背景色 e.Row.Attributes.Add("onmouseover", "c=this.style.backgroundColor;this.style.backgroundColor='#00A9FF'"); //当鼠标移开时还原背景色 e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor=c"); //点击一个当前行出现弹出框 e.Row.Attributes.Add("onclick", "alert(123)"); e.Row.Attributes.CssStyle.Add("cursor", "hand"); } } }

  然后就是add("属性","结果");

<!DOCTYPE html>
<html>
<body>
获取 js中函数的返回值
<p>本例调用的函数会执行一个计算,然后返回结果:</p>

<p id="demo"></p>

<script>
function myFunction(a,b)
{
return a*b;
}

document.getElementById("demo").innerHTML=myFunction(4,3);
</script>

</body>
</html>

  

 这个讲的全

C#中 Attributes的用法

猜你喜欢

转载自www.cnblogs.com/ZkbFighting/p/9248279.html
Row