开发者

How to show Selected linkbutton amongs set of linkbuttons in asp.net?

i have one aspx page on which. set of linkbuttons on it.

linkbutton1

linkbutton2

linkbutton3

linkbutton4

linkbutton5

if i click on any of them. it should be highlighted.

These开发者_运维技巧 linkbuttons are in the table.

thanks for any help.


If you add a CssClass to any of your linkbuttons, something like

<asp:LinkButton ID="LinkButton1" runat="server" CssClass="linkbtn" />

You can define the highlighted style in CSS like

.linkbtn .highlighted { color: red; }

and use some javascript to toggle classes. In jQuery it would look like:

$(".linkbtn").click(function () {
   $(".linkbtn").removeClass("highlighted");
   $(this).addClass("highlighted");
});

in ASP.Net just use

<asp:LinkButton id="LinkButton4" OnClick="LinkButton4_Click" runat="server"/>

and in codebehind

private void SetHighlighted(LinkButton btn)
{
  LinkButton1.CssClass = "";
  LinkButton2.CssClass = "";
  LinkButton3.CssClass = "";
  LinkButton4.CssClass = "";
  LinkButton5.CssClass = "";

  btn.CssClass = "highlighted";
}

protected void LinkButton4_Click(object sender, EventArgs e)
{
  SetHighlighted((LinkButton)sender);
}

do this for every linkbutton


you can easily take care of this with css.

when you handle the linkbutton click event set the CSSClass property of the linkbutton to a class which differentiates it from the other linkbuttons in the list.

for instance, on page load you can have all linkbuttons CSSClass property set to Link and have this class defined to be your standard look and feel for hyperlinks. 8pt, tahoma, underlined etc.

create another class called LinkSelected and have it be 8pt, tahoma, underlined, and bold.

in your linkbutton click handler set myLink.CSSClass="LinkSelected"; or ((LinkButton)sender).CSSClass="LinkSelected";

you can define Link and LinkSelected class either inline (not recommended) or in a separate .css file.

give it a try and let me know if you need more details.


I build the same in my pages the last weeks often.

As I see you have 2 options, regarding your code behind, that I don't know:

1) Your link button are linked to a special site (as hyperlinks). Than you can found out by the actual site which is clicked an hover it.

2) Your linkbutton only acitvate code, than you can make a normal "linkbutton1.Font.Bold = true" or something like this.

If you want it by CSS as my knowlegde it is not possible, because there are not rendered as a -tag.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜