【ASP.NET奇效】为动态创建的表格添加鼠标事件
【ASP.NET特效】为动态创建的表格添加鼠标事件
1.WEB页代码如下
2.cs中代码如下:
请问如何为新创建的表格添加如下鼠标代码:
------解决方案--------------------
1.WEB页代码如下
- HTML code
<asp:table id=table1 runat=server> <asp:tablerow> <asp:tablecell id=newbtn runat=server> //注意这个id . .
2.cs中代码如下:
- C# code
System.Web.UI.WebControls.Button btnlastYV = new System.Web.UI.WebControls.Button(); btnlastYV.Text = "OK"; btnlastYV.ID = "btnlastYV"; btnlastYV.Click +=new EventHandler(btnlastYV_Click); newbtn.Controls.Add(btnlastYV); //添加button到cell
请问如何为新创建的表格添加如下鼠标代码:
- HTML code
onMouseOver="this.style.backgroundColor='#E1E8E8';return true;" onMouseOut="this.style.backgroundColor='#fbfbfb';"
------解决方案--------------------
- C# code
newbtn.Attributes.Add("onMouseOver", "this.style.backgroundColor='#E1E8E8';return true;"); newbtn.Attributes.Add("onMouseOut","this.style.backgroundColor='#fbfbfb';")