将CSS添加到listview中的选定链接按钮 [英] Add CSS to selected link button inside listview
问题描述
您好,
我有一个asp.net webform应用程序,在listview中有一个链接按钮。
我想要什么做的是突出显示/更改Itemcommand上所选按钮的颜色。
我尝试了很多解决方案而没有运气。它会改变颜色,但当我点击另一个按钮时它不会改变。
任何帮助都会非常感激。
谢谢
Samira
我的尝试:
我试图在ItemCommand,ItemDataBound和按钮点击上更改所选/点击按钮的颜色。
listview内的链接按钮:
< ; asp:ListView runat =serverID =subs_viewDataSourceID =SubsFilterSqlDataSourceOnItemCommand =subs_view_ItemCommandOnItemDataBound =subs_view_ItemDataBound>
< ItemTemplate>
< asp:LinkButton cssClass =col-md-9 link-btnrunat =serverID =btnSubsCommandName =subsCommandArgument ='<%#Eval(code)% >'Text ='<%#Eval(SubCat_CountItems)%>'OnClick =btnSubs_Click> < / ASP:LinkButton的>
< / ItemTemplate>
< / asp:ListView>
我尝试以不同方式更改颜色:
protected void subs_view_ItemCommand(object sender,ListViewCommandEventArgs e)
{
if(e.CommandName ==subs)
{
LinkButton linkbtn =(LinkButton)e。 Item.FindControl( btnSubs);
linkbtn.ForeColor = System.Drawing.Color.Red;
//点击另一个按钮时颜色保持红色
}
}
protected void btnSubs_Click(object sender,EventArgs e)
{
//subs_view.DataBind();
// LinkButton mybtn =(LinkButton)发送者;
////mybtn.ForeColor = System.Drawing.Color.Black;
//mybtn.ForeColor = System.Drawing.Color.Red;
}
-
protected void subs_view_ItemDataBound(object sender,ListViewItemEventArgs e)
{
// LinkButton btnSubs =(LinkButton)e.Item.FindControl(btnSubs);
//btnSubs.ForeColor = System.Drawing.Color.Black;
}
您可以尝试设置ViewStateMode =已禁用$ p ListView控件上的$ p>。在按钮点击,回发的情况下,原始颜色将使用默认颜色而不是ViewState中保存的颜色进行恢复。
Hello,
I have an asp.net webform application that has a link button inside a listview.
What I want to do is to highlight/change color of the selected button on Itemcommand.
I have tried a lot of solutions with no luck. It changes the color but it doesn't change back when i click another button.
Any help will be so much appreciated.
Thanks
Samira
What I have tried:
I tried to change color of the selected/clicked button on ItemCommand , ItemDataBound and button click.
Link button inside listview:
<asp:ListView runat="server" ID="subs_view" DataSourceID="SubsFilterSqlDataSource" OnItemCommand="subs_view_ItemCommand" OnItemDataBound= "subs_view_ItemDataBound"> <ItemTemplate> <asp:LinkButton cssClass="col-md-9 link-btn" runat="server" ID="btnSubs" CommandName="subs" CommandArgument='<%#Eval("code") %>' Text='<%#Eval("SubCat_CountItems") %>' OnClick="btnSubs_Click"> </asp:LinkButton> </ItemTemplate> </asp:ListView>
I tried to change colors in different ways:
protected void subs_view_ItemCommand(object sender, ListViewCommandEventArgs e) { if (e.CommandName == "subs") { LinkButton linkbtn = (LinkButton)e.Item.FindControl("btnSubs"); linkbtn.ForeColor = System.Drawing.Color.Red; //the color stays red when clicking another button } }
protected void btnSubs_Click(object sender, EventArgs e) { //subs_view.DataBind(); //LinkButton mybtn = (LinkButton)sender; ////mybtn.ForeColor = System.Drawing.Color.Black; //mybtn.ForeColor = System.Drawing.Color.Red; }
--
protected void subs_view_ItemDataBound(object sender, ListViewItemEventArgs e) { //LinkButton btnSubs = (LinkButton)e.Item.FindControl("btnSubs"); //btnSubs.ForeColor = System.Drawing.Color.Black; }
You can try to set theViewStateMode="Disabled"on the ListView control. That case on button click, post back happen, the original color will be restored using the default color instead of the color saved in ViewState.
这篇关于将CSS添加到listview中的选定链接按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!