By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,361 Members | 1,700 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,361 IT Pros & Developers. It's quick & easy.

Change Hyperlink style dynamically

P: n/a
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")).Mer geStyle(string) =
"font-size:" + strSize;

}
}

}

Thanks a lot,

Imran.
Nov 19 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
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")).Mer geStyle(string) =
"font-size:" + strSize;

}
}

}

Thanks a lot,

Imran.

Nov 19 '05 #2

P: n/a
Thanks Clint Hill, that was a quick and good solution, worked great thanks.

Imran.

"Clint Hill" <cl********@nospamath3osoftware.com> wrote in message
news:CE**********************************@microsof t.com...
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")).Mer geStyle(string) =
"font-size:" + strSize;

}
}

}

Thanks a lot,

Imran.

Nov 19 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.