Change Hyperlink style dynamically

I

Imran Aziz

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.
 
G

Guest

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.
 
I

Imran Aziz

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

Imran.

Clint Hill said:
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 said:
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.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

Forum statistics

Threads
473,755
Messages
2,569,539
Members
45,024
Latest member
ARDU_PROgrammER

Latest Threads

Top