asp.net 如何使datagrid中当鼠标移上去时行变色??急,在线等~

如题.<asp:datagridid="DataGrid1"runat="server"Width="100%"GridLines="None"HeaderStyle-C... 如题.
<asp:datagrid id="DataGrid1" runat="server" Width="100%" GridLines="None" HeaderStyle-CssClass="searchtitle"Height="100px" AllowCustomPaging="True" AllowSorting="True" AllowPaging="True" PageSize="20"AutoGenerateColumns="False" ShowFooter="True">
<AlternatingItemStyle BackColor="White"></AlternatingItemStyle>
<ItemStyle CssClass="searchwrite" BackColor="#EDF3FE"></ItemStyle>
<HeaderStyle Font-Bold="True" Height="30px" ForeColor="#545655" CssClass="searchtitle"></HeaderStyle>
<Columns>
<asp:BoundColumn DataField="id" SortExpression="id" HeaderText="ID">
<HeaderStyle Font-Bold="True" Width="30px"></HeaderStyle>
</asp:BoundColumn>
<asp:TemplateColumn SortExpression="name" HeaderText="医院名称">
<HeaderStyle Width="90px"></HeaderStyle>
</asp:TemplateColumn>
<asp:ButtonColumn Text="删除" CommandName="Delete">
<HeaderStyle Width="60px"></HeaderStyle>
</asp:ButtonColumn>
</Columns>
<PagerStyle PageButtonCount="100" Mode="NumericPages"></PagerStyle>
</asp:datagrid>
=======================
代码我是拷贝过来的,但是这样是不对的,没有反应,但我还是贴上来,
// ItemDataBound事件
private void changeRowColor(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)
{
//如果是数据项并且是交替项
if(e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
{
//添加自定义属性,当鼠标移过来时设置该行的背景色为"6699ff",并保存原背景色
e.Item.Attributes.Add("onmouseover","currentcolor=this.style.backgroundColor;this.style.backgroundColor='#6699ff'");
//添加自定义属性,当鼠标移走时还原该行的背景色
e.Item.Attributes.Add("onmouseout","this.style.backgroundColor=currentcolor");

}
}大家帮我看下,如果帮我解决可追加分分~~~谢谢!!!
展开
 我来答
stu216
2009-03-31
知道答主
回答量:11
采纳率:0%
帮助的人:7.2万
展开全部
添加RowDataBound事件就行了
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
//设置行颜色
e.Row.Attributes.Add("onmouseover", "currentcolor=this.style.backgroundColor;this.style.backgroundColor='#ffccff'");
//添加自定义属性,当鼠标移走时还原该行的背景色
e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor=currentcolor");
}
}
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
百度网友76e521f
2009-04-01 · TA获得超过3304个赞
知道小有建树答主
回答量:262
采纳率:0%
帮助的人:119万
展开全部
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
e.Row.Attributes.Add("onmouseover", "color=this.style.backgroundColor;this.style.backgroundColor='lavender'");
e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor=color");
}
}

你上面的事件写错了,在GridView的RowDataBound事件里面写上上面的代码
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
茂烟f
2009-03-30 · TA获得超过329个赞
知道小有建树答主
回答量:666
采纳率:0%
帮助的人:649万
展开全部
<asp:datagrid id="DataGrid1" runat="server" Width="100%" GridLines="None" HeaderStyle-CssClass="searchtitle"Height="100px" AllowCustomPaging="True" AllowSorting="True" AllowPaging="True" PageSize="20"AutoGenerateColumns="False" ShowFooter="True">
没有添加事件
应添加时间 OnRowDataBound="changeRowColor"
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
仵天菱C
2009-03-30 · TA获得超过233个赞
知道小有建树答主
回答量:173
采纳率:0%
帮助的人:178万
展开全部
在ItemDataBound事件里 调用 changeRowColor(sender,e)
本回答被提问者采纳
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
收起 1条折叠回答
收起 更多回答(2)
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式