datalist中的linkbutton样式问题。谢谢!
datalist中放了个linkbutton,现在我想点击linkbutton后当前点击的样式变成有底色、文字变红色,其他的linkbutton样式底色清空、文字还原成原...
datalist中放了个linkbutton,现在我想点击linkbutton后当前点击的样式变成有底色、文字变红色,其他的linkbutton样式底色清空、文字还原成原来定义的颜色。
貌似你说的这个方法不行!这个是鼠标移动变化颜色,我问的是点击后当前项变css其他的全部恢复原来定义的css 展开
貌似你说的这个方法不行!这个是鼠标移动变化颜色,我问的是点击后当前项变css其他的全部恢复原来定义的css 展开
2个回答
展开全部
给你写了个例子,不知道可以帮助你不
Default.aspx文件:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:DataList ID="DL_Test" runat="server" onitemcommand="DL_Test_ItemCommand"
onitemdatabound="DL_Test_ItemDataBound">
<ItemTemplate>
<asp:LinkButton ID="LinkButton1" runat="server" Text='<%# Bind("value") %>'
CommandArgument='<%# Bind("value") %>' ForeColor=Black></asp:LinkButton>
</ItemTemplate>
</asp:DataList>
<br />
<asp:Label ID="LB_Test" runat="server" Text="Label"></asp:Label>
</div>
</form>
</body>
</html>
Default.aspx.cs文件:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
public partial class _Default : System.Web.UI.Page
{
DataTable dt = new DataTable();
DataRow dr;
protected void Page_Load(object sender, EventArgs e)
{
dt.Columns.Add(new DataColumn("key", typeof(Int32)));
dt.Columns.Add(new DataColumn("value", typeof(string)));
for (int i = 0; i < 5; i++)
{
dr = dt.NewRow();
dr[0] = i;
dr[1] = "第" + i + "项";
dt.Rows.Add(dr);
}
BindDL(dt);
if (!IsPostBack)
{
ChangeWhenSelected(0);
}
}
void BindDL(DataTable a)
{
DL_Test.DataSource = a;
DL_Test.DataBind();
}
protected void DL_Test_ItemCommand(object source, DataListCommandEventArgs e)
{
ChangeWhenSelected(e.Item.ItemIndex);
}
protected void DL_Test_ItemDataBound(object sender, DataListItemEventArgs e)
{//改变所有行的颜色为默认
if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
{
LinkButton lbtn = (LinkButton)e.Item.FindControl("LinkButton1");
lbtn.ForeColor = System.Drawing.Color.Black;
}
}
void ChangeWhenSelected(int num)
{
LinkButton mm = (LinkButton)DL_Test.Items[num].FindControl("LinkButton1");
LB_Test.Text = mm.CommandArgument;
mm.ForeColor = System.Drawing.Color.Red;
}
}
Default.aspx文件:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:DataList ID="DL_Test" runat="server" onitemcommand="DL_Test_ItemCommand"
onitemdatabound="DL_Test_ItemDataBound">
<ItemTemplate>
<asp:LinkButton ID="LinkButton1" runat="server" Text='<%# Bind("value") %>'
CommandArgument='<%# Bind("value") %>' ForeColor=Black></asp:LinkButton>
</ItemTemplate>
</asp:DataList>
<br />
<asp:Label ID="LB_Test" runat="server" Text="Label"></asp:Label>
</div>
</form>
</body>
</html>
Default.aspx.cs文件:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
public partial class _Default : System.Web.UI.Page
{
DataTable dt = new DataTable();
DataRow dr;
protected void Page_Load(object sender, EventArgs e)
{
dt.Columns.Add(new DataColumn("key", typeof(Int32)));
dt.Columns.Add(new DataColumn("value", typeof(string)));
for (int i = 0; i < 5; i++)
{
dr = dt.NewRow();
dr[0] = i;
dr[1] = "第" + i + "项";
dt.Rows.Add(dr);
}
BindDL(dt);
if (!IsPostBack)
{
ChangeWhenSelected(0);
}
}
void BindDL(DataTable a)
{
DL_Test.DataSource = a;
DL_Test.DataBind();
}
protected void DL_Test_ItemCommand(object source, DataListCommandEventArgs e)
{
ChangeWhenSelected(e.Item.ItemIndex);
}
protected void DL_Test_ItemDataBound(object sender, DataListItemEventArgs e)
{//改变所有行的颜色为默认
if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
{
LinkButton lbtn = (LinkButton)e.Item.FindControl("LinkButton1");
lbtn.ForeColor = System.Drawing.Color.Black;
}
}
void ChangeWhenSelected(int num)
{
LinkButton mm = (LinkButton)DL_Test.Items[num].FindControl("LinkButton1");
LB_Test.Text = mm.CommandArgument;
mm.ForeColor = System.Drawing.Color.Red;
}
}
网易云信
2023-12-06 广告
2023-12-06 广告
UIkit是一套轻量级、模块化且易于使用的开源UI组件库,由YOOtheme团队开发。它提供了丰富的界面元素,包括按钮、表单、表格、对话框、滑块、下拉菜单、选项卡等等,适用于各种类型的网站和应用程序。UIkit还支持响应式设计,可以根据不同...
点击进入详情页
本回答由网易云信提供
展开全部
DataIist_RowDataBound事件
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
e.Row.Attributes["onmouseout"] = "javascript:this.style.backgroundColor='#E8F4FF';";
e.Row.Attributes["onmouseover"] = "javascript:this.style.backgroundColor='#d9a88f';cursor='hand';";
}
else
{
e.Row.Attributes["onmouseout"] = "javascript:this.style.backgroundColor='#ffffff';";
e.Row.Attributes["onmouseover"] = "javascript:this.style.backgroundColor='#93BEE2';cursor='hand';";
}
}
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
e.Row.Attributes["onmouseout"] = "javascript:this.style.backgroundColor='#E8F4FF';";
e.Row.Attributes["onmouseover"] = "javascript:this.style.backgroundColor='#d9a88f';cursor='hand';";
}
else
{
e.Row.Attributes["onmouseout"] = "javascript:this.style.backgroundColor='#ffffff';";
e.Row.Attributes["onmouseover"] = "javascript:this.style.backgroundColor='#93BEE2';cursor='hand';";
}
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询