Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Change Hyperlink style dynamically

Reply
Thread Tools

Change Hyperlink style dynamically

 
 
Imran Aziz
Guest
Posts: n/a
 
      09-02-2005
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.


 
Reply With Quote
 
 
 
 
=?Utf-8?B?Q2xpbnQgSGlsbA==?=
Guest
Posts: n/a
 
      09-02-2005
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.
>
>
>

 
Reply With Quote
 
 
 
 
Imran Aziz
Guest
Posts: n/a
 
      09-02-2005
Thanks Clint Hill, that was a quick and good solution, worked great thanks.

Imran.

"Clint Hill" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
>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.
>>
>>
>>



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to dynamically change the style sheet based on browser type Rob Roberts ASP .Net 2 01-21-2006 12:38 AM
how to change style of a clicked-on hyperlink Tim_Mac Javascript 4 05-21-2005 05:05 PM
dynamically change style width of object TJS ASP .Net 2 04-04-2005 06:27 AM
Need help with Style conversion from Style object to Style key/value collection. Ken Varn ASP .Net Building Controls 0 04-26-2004 07:06 PM
Dynamically Hyperlink and Event Handler for the Hyperlink ? Ken ASP .Net Datagrid Control 1 08-15-2003 11:38 PM



Advertisments