Change Hyperlink style dynamically

Discussion in 'ASP .Net' started by Imran Aziz, Sep 2, 2005.

  1. Imran Aziz

    Imran Aziz Guest

    Hello All,

    I want to change the size of my hyper lnks in a repeater control dynamially
    using the onItemBound event, as under, but cannot seem to understand how to
    alter the properties to do that.



    <asp:HiddenField ID="maxFrequency" runat="server" />

    <ASP:Repeater id="repTags" runat="server" OnItemDataBound="ShowFrequery" >

    <ItemTemplate>

    <a id="lnkFeedTags" href='<%# "../resources/showentries.aspx?strTag=" +
    Server.UrlEncode((((DataRowView)Container.DataItem)["sTag"]).ToString())%>'
    runat="server" ><%# DataBinder.Eval(Container.DataItem,
    "sTag").ToString()%></a>

    <asp:HiddenField ID="lnkFeedFrequency" runat="server" Value='<%#
    DataBinder.Eval(Container.DataItem, "nTagsCount").ToString()%>'/>

    </ItemTemplate>

    </ASP:Repeater>

    Code behind is

    public void ShowFrequery(Object sender, RepeaterItemEventArgs e)

    {

    if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType ==
    ListItemType.AlternatingItem)

    {

    string strValue =
    ((HiddenField)e.Item.FindControl("lnkFeedFrequency")).Value;

    string strMax = maxFrequency.Value;

    if ((strValue != "") && (strMax != ""))

    {

    string strSize = string.Empty;

    int frqSize = (int.Parse(strValue) / int.Parse(maxFrequency.Value)) * 7;

    switch (frqSize)

    {

    case 1: strSize = "x-small";

    break;

    case 2: strSize = "small";

    break;

    case 3: strSize = "smaller";

    break;

    case 4: strSize = "medium";

    break;

    case 5: strSize = "larger";

    break;

    case 6: strSize = "large";

    break;

    case 7: strSize = "x-large";

    break;

    default: strSize = "x-small";

    break;

    }

    Style s = new Style();


    ((HyperLink)e.Item.FindControl("lnkFeedTags")).MergeStyle(string) =
    "font-size:" + strSize;

    }


    }



    }



    Thanks a lot,

    Imran.
    Imran Aziz, Sep 2, 2005
    #1
    1. Advertising

  2. I would look to change the name of the CSS class the link uses, then setup
    CSS classes with these different styles, rather than use MergeStyle.
    --
    Clint Hill MCAD
    H3O Software
    http://www.h3osoftware.com


    "Imran Aziz" wrote:

    > Hello All,
    >
    > I want to change the size of my hyper lnks in a repeater control dynamially
    > using the onItemBound event, as under, but cannot seem to understand how to
    > alter the properties to do that.
    >
    >
    >
    > <asp:HiddenField ID="maxFrequency" runat="server" />
    >
    > <ASP:Repeater id="repTags" runat="server" OnItemDataBound="ShowFrequery" >
    >
    > <ItemTemplate>
    >
    > <a id="lnkFeedTags" href='<%# "../resources/showentries.aspx?strTag=" +
    > Server.UrlEncode((((DataRowView)Container.DataItem)["sTag"]).ToString())%>'
    > runat="server" ><%# DataBinder.Eval(Container.DataItem,
    > "sTag").ToString()%></a>
    >
    > <asp:HiddenField ID="lnkFeedFrequency" runat="server" Value='<%#
    > DataBinder.Eval(Container.DataItem, "nTagsCount").ToString()%>'/>
    >
    > </ItemTemplate>
    >
    > </ASP:Repeater>
    >
    > Code behind is
    >
    > public void ShowFrequery(Object sender, RepeaterItemEventArgs e)
    >
    > {
    >
    > if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType ==
    > ListItemType.AlternatingItem)
    >
    > {
    >
    > string strValue =
    > ((HiddenField)e.Item.FindControl("lnkFeedFrequency")).Value;
    >
    > string strMax = maxFrequency.Value;
    >
    > if ((strValue != "") && (strMax != ""))
    >
    > {
    >
    > string strSize = string.Empty;
    >
    > int frqSize = (int.Parse(strValue) / int.Parse(maxFrequency.Value)) * 7;
    >
    > switch (frqSize)
    >
    > {
    >
    > case 1: strSize = "x-small";
    >
    > break;
    >
    > case 2: strSize = "small";
    >
    > break;
    >
    > case 3: strSize = "smaller";
    >
    > break;
    >
    > case 4: strSize = "medium";
    >
    > break;
    >
    > case 5: strSize = "larger";
    >
    > break;
    >
    > case 6: strSize = "large";
    >
    > break;
    >
    > case 7: strSize = "x-large";
    >
    > break;
    >
    > default: strSize = "x-small";
    >
    > break;
    >
    > }
    >
    > Style s = new Style();
    >
    >
    > ((HyperLink)e.Item.FindControl("lnkFeedTags")).MergeStyle(string) =
    > "font-size:" + strSize;
    >
    > }
    >
    >
    > }
    >
    >
    >
    > }
    >
    >
    >
    > Thanks a lot,
    >
    > Imran.
    >
    >
    >
    =?Utf-8?B?Q2xpbnQgSGlsbA==?=, Sep 2, 2005
    #2
    1. Advertising

  3. Imran Aziz

    Imran Aziz Guest

    Thanks Clint Hill, that was a quick and good solution, worked great thanks.

    Imran.

    "Clint Hill" <> wrote in message
    news:...
    >I would look to change the name of the CSS class the link uses, then setup
    > CSS classes with these different styles, rather than use MergeStyle.
    > --
    > Clint Hill MCAD
    > H3O Software
    > http://www.h3osoftware.com
    >
    >
    > "Imran Aziz" wrote:
    >
    >> Hello All,
    >>
    >> I want to change the size of my hyper lnks in a repeater control
    >> dynamially
    >> using the onItemBound event, as under, but cannot seem to understand how
    >> to
    >> alter the properties to do that.
    >>
    >>
    >>
    >> <asp:HiddenField ID="maxFrequency" runat="server" />
    >>
    >> <ASP:Repeater id="repTags" runat="server" OnItemDataBound="ShowFrequery"
    >> >

    >>
    >> <ItemTemplate>
    >>
    >> <a id="lnkFeedTags" href='<%# "../resources/showentries.aspx?strTag=" +
    >> Server.UrlEncode((((DataRowView)Container.DataItem)["sTag"]).ToString())%>'
    >> runat="server" ><%# DataBinder.Eval(Container.DataItem,
    >> "sTag").ToString()%></a>
    >>
    >> <asp:HiddenField ID="lnkFeedFrequency" runat="server" Value='<%#
    >> DataBinder.Eval(Container.DataItem, "nTagsCount").ToString()%>'/>
    >>
    >> </ItemTemplate>
    >>
    >> </ASP:Repeater>
    >>
    >> Code behind is
    >>
    >> public void ShowFrequery(Object sender, RepeaterItemEventArgs e)
    >>
    >> {
    >>
    >> if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType ==
    >> ListItemType.AlternatingItem)
    >>
    >> {
    >>
    >> string strValue =
    >> ((HiddenField)e.Item.FindControl("lnkFeedFrequency")).Value;
    >>
    >> string strMax = maxFrequency.Value;
    >>
    >> if ((strValue != "") && (strMax != ""))
    >>
    >> {
    >>
    >> string strSize = string.Empty;
    >>
    >> int frqSize = (int.Parse(strValue) / int.Parse(maxFrequency.Value)) * 7;
    >>
    >> switch (frqSize)
    >>
    >> {
    >>
    >> case 1: strSize = "x-small";
    >>
    >> break;
    >>
    >> case 2: strSize = "small";
    >>
    >> break;
    >>
    >> case 3: strSize = "smaller";
    >>
    >> break;
    >>
    >> case 4: strSize = "medium";
    >>
    >> break;
    >>
    >> case 5: strSize = "larger";
    >>
    >> break;
    >>
    >> case 6: strSize = "large";
    >>
    >> break;
    >>
    >> case 7: strSize = "x-large";
    >>
    >> break;
    >>
    >> default: strSize = "x-small";
    >>
    >> break;
    >>
    >> }
    >>
    >> Style s = new Style();
    >>
    >>
    >> ((HyperLink)e.Item.FindControl("lnkFeedTags")).MergeStyle(string) =
    >> "font-size:" + strSize;
    >>
    >> }
    >>
    >>
    >> }
    >>
    >>
    >>
    >> }
    >>
    >>
    >>
    >> Thanks a lot,
    >>
    >> Imran.
    >>
    >>
    >>
    Imran Aziz, Sep 2, 2005
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. TJS
    Replies:
    2
    Views:
    2,279
  2. Rob Roberts
    Replies:
    2
    Views:
    10,854
    Rob Roberts
    Jan 21, 2006
  3. Ken Varn
    Replies:
    0
    Views:
    443
    Ken Varn
    Apr 26, 2004
  4. Ken
    Replies:
    1
    Views:
    369
    Alvin Bruney
    Aug 16, 2003
  5. Tim_Mac
    Replies:
    4
    Views:
    100
    Tim_Mac
    May 21, 2005
Loading...

Share This Page