Showing posts with label css. Show all posts
Showing posts with label css. Show all posts

Thursday, March 29, 2012

Set css class on list box option

Hi,

I want to programatically set the css class on a single list item. I tried the following code but it does nothing...


<html>
<script language="VB" runat="server"
Sub Page_Load(Src As Object, E As EventArgs)
categories.Items(0).Attributes.Add("class", "option.primary")
End Sub

</script
<style>
.primary {background-color:green;color:red; }
</style
<body>
<form runat="server">
<asp:listbox id="categories" Runat="server" SelectionMode="Multiple" Rows="6" Width="400">
<asp:listItem>Item 1</asp:listItem>
</asp:listbox>
</form>
</body>
</html>

Does anyone know how to achieve this?

WT.use the "cssclass" property of the listbox, then you can set it without doing the attributes.add thing.
<option> elements do not have class attributes, but it *is* strange that it doesn't write it out anyway. If you look at the rendered HTML, it probably reads:

<select name="categories">
<option value="Item 1">Item 1</option
That is because, as said, option elements don't have class attributes. Additionally, you're specifying "option.primary" where really the css class you want to use is "primary". If you want to add the class to the whole categories listbox, you could. And an easier way is to use this syntax:


categories.CssClass = "primary"

Which will work just the same as:


categories.Attributes.Add("class","primary")

Thanks for the replies.

I presume that the listItems not rendering their attributes must be a bug.

Looking at the source for the ListBox control, it doesn't appear to be rendering the attributes of its list items. Thus, I'll override the 'RenderContents' method or something and get the attributes rendered.
I think it is a bug too,

but the class browser indicated that the attributes property of the ListItem is readonly which would explain the attributes not being added to the listitem... maybe it is by design.

Monday, March 26, 2012

Set default Tag Prefix and CSS?

Hello,
I am creating a web server control derived from
datagrid for the first time. Now I would like to set the
prefix of my control by default to SK instead of CC1. Is
that possible? The other question is that my datagrid
should use a default stylesheet. I have set the cssclass
property of all items which I want to change. BUT I am not
setting the link tag in the head section to my css. I dont
want to do that. I would like to do that direclty in my
component. Is that possible?
ThanksAlternatingItemStyle
ItemStyle
HeaderStyle
footerstyle
if u set css for these four element, css will apply for u're componet. plz
see blow , I explained how we hve to use sample class...
<asp:datagrid id="dgActivity" runat="server" AllowPaging="True"
Class="DataGridStyle" Width="100%"
CellPadding="2" PageSize="30" AutoGenerateColumns="False" AllowSorting="True
">
<AlternatingItemStyle
CssClass="DataGridAlterItemStyle"></AlternatingItemStyle>
<ItemStyle CssClass="DataGridItemStyle"></ItemStyle>
<HeaderStyle CssClass="DataGridHeaderStyle"></HeaderStyle>
.DataGridStyle
{
border-color : White;
border-style : solid;
}
.DataGridStyle td
{
border-color : White;
border-style : solid;
}
.DataGridHeaderStyle
{
font-size : 8pt;
font-family : Verdana;
font-weight : bold;
vertical-align : middle;
text-align : center;
color:White;
text-align : left;
background-color : "#6487DC";
}
.DataGridHeaderStyle a
{
font-size : 8pt;
font-family : Verdana;
font-weight : bold;
vertical-align : middle;
text-align : center;
color:White;
text-align : left;
background-color : "#6487DC";
}
.DataGridHeaderStyle a:link
{
font-size : 8pt;
font-family : Verdana;
font-weight : bold;
vertical-align : middle;
text-align : center;
color:White;
text-align : left;
background-color : "#6487DC";
}
.DataGridHeaderStyle a:hover
{
font-size : 8pt;
font-family : Verdana;
font-weight : bold;
vertical-align : middle;
text-align : center;
color:White;
text-align : left;
background-color : "#6487DC";
}
.DataGridHeaderStyle a:visited
{
font-size : 8pt;
font-family : Verdana;
font-weight : bold;
vertical-align : middle;
text-align : center;
color:White;
text-align : left;
background-color : "#6487DC";
}
"SK" wrote:

> Hello,
> I am creating a web server control derived from
> datagrid for the first time. Now I would like to set the
> prefix of my control by default to SK instead of CC1. Is
> that possible? The other question is that my datagrid
> should use a default stylesheet. I have set the cssclass
> property of all items which I want to change. BUT I am not
> setting the link tag in the head section to my css. I dont
> want to do that. I would like to do that direclty in my
> component. Is that possible?
> Thanks
>
Hello SK,
Look at the [assembly:TagPrefix] attribute. You'll need to reference System.Web.UI,
if you're not already.
[assembly:TagPrefix("YourNamespace", "YourPrefix")]
Matt Berther
http://www.mattberther.com

> Hello,
> I am creating a web server control derived from datagrid for the
> first time. Now I would like to set the prefix of my control by
> default to SK instead of CC1. Is that possible? The other question is
> that my datagrid should use a default stylesheet. I have set the
> cssclass property of all items which I want to change. BUT I am not
> setting the link tag in the head section to my css. I dont want to do
> that. I would like to do that direclty in my component. Is that
> possible?
> Thanks
>

Set default Tag Prefix and CSS?

Hello,

I am creating a web server control derived from
datagrid for the first time. Now I would like to set the
prefix of my control by default to SK instead of CC1. Is
that possible? The other question is that my datagrid
should use a default stylesheet. I have set the cssclass
property of all items which I want to change. BUT I am not
setting the link tag in the head section to my css. I dont
want to do that. I would like to do that direclty in my
component. Is that possible?

ThanksAlternatingItemStyle
ItemStyle
HeaderStyle
footerstyle

if u set css for these four element, css will apply for u're componet. plz
see blow , I explained how we hve to use sample class...
<asp:datagrid id="dgActivity" runat="server" AllowPaging="True"
Class="DataGridStyle" Width="100%"
CellPadding="2" PageSize="30" AutoGenerateColumns="False" AllowSorting="True">
<AlternatingItemStyle
CssClass="DataGridAlterItemStyle"></AlternatingItemStyle>
<ItemStyle CssClass="DataGridItemStyle"></ItemStyle>
<HeaderStyle CssClass="DataGridHeaderStyle"></HeaderStyle
..DataGridStyle
{
border-color : White;
border-style : solid;
}
..DataGridStyle td
{
border-color : White;
border-style : solid;
}
..DataGridHeaderStyle
{
font-size : 8pt;
font-family : Verdana;
font-weight : bold;
vertical-align : middle;
text-align : center;
color:White;
text-align : left;
background-color : "#6487DC";

}
..DataGridHeaderStyle a
{
font-size : 8pt;
font-family : Verdana;
font-weight : bold;
vertical-align : middle;
text-align : center;
color:White;
text-align : left;
background-color : "#6487DC";
}
..DataGridHeaderStyle a:link
{
font-size : 8pt;
font-family : Verdana;
font-weight : bold;
vertical-align : middle;
text-align : center;
color:White;
text-align : left;
background-color : "#6487DC";
}
..DataGridHeaderStyle a:hover
{
font-size : 8pt;
font-family : Verdana;
font-weight : bold;
vertical-align : middle;
text-align : center;
color:White;
text-align : left;
background-color : "#6487DC";
}
..DataGridHeaderStyle a:visited
{
font-size : 8pt;
font-family : Verdana;
font-weight : bold;
vertical-align : middle;
text-align : center;
color:White;
text-align : left;
background-color : "#6487DC";
}

"SK" wrote:

> Hello,
> I am creating a web server control derived from
> datagrid for the first time. Now I would like to set the
> prefix of my control by default to SK instead of CC1. Is
> that possible? The other question is that my datagrid
> should use a default stylesheet. I have set the cssclass
> property of all items which I want to change. BUT I am not
> setting the link tag in the head section to my css. I dont
> want to do that. I would like to do that direclty in my
> component. Is that possible?
> Thanks
Hello SK,

Look at the [assembly:TagPrefix] attribute. You'll need to reference System.Web.UI,
if you're not already.

[assembly:TagPrefix("YourNamespace", "YourPrefix")]

--
Matt Berther
http://www.mattberther.com

> Hello,
> I am creating a web server control derived from datagrid for the
> first time. Now I would like to set the prefix of my control by
> default to SK instead of CC1. Is that possible? The other question is
> that my datagrid should use a default stylesheet. I have set the
> cssclass property of all items which I want to change. BUT I am not
> setting the link tag in the head section to my css. I dont want to do
> that. I would like to do that direclty in my component. Is that
> possible?
> Thanks

Tuesday, March 13, 2012

Set page stylesheet in code-behind?

Let's say we want to change the page style each day:
<HEAD>
.
.
.
<style type="text/css" media="all">@dotnet.itags.org.import url( TuesdayStyles.css );
</style>
</HEAD>
Is it possible to do this in *code-behind* ? Can you write the <STYLE>
directive into the <HEAD></HEAD> section of the page?
Thanks
Liamin 2.0 it's easier...they have a method just for this.
in 1.1, you can plunk a literal down and use Literal.Text = "aaaaa"
Karl
MY ASP.Net tutorials
http://www.openmymind.net/
"Liam" <Liam@.zzzz.net> wrote in message
news:ORITw$TFGHA.3100@.tk2msftngp13.phx.gbl...
> Let's say we want to change the page style each day:
> <HEAD>
> .
> .
> .
> <style type="text/css" media="all">@.import url( TuesdayStyles.css );
> </style>
> </HEAD>
> Is it possible to do this in *code-behind* ? Can you write the <STYLE>
> directive into the <HEAD></HEAD> section of the page?
> Thanks
> Liam
Karl,
Happen to have the name of that method?
In 2.0? It's under Page.Header.StyleSheet
Page.Header is great in 2.0...check it out:
http://msdn2.microsoft.com/en-us/li...
rs.aspx
Karl
--
MY ASP.Net tutorials
http://www.openmymind.net/
"The Colonel" <colonelangus@.budweiser.com> wrote in message
news:1136832866.985107.80350@.o13g2000cwo.googlegroups.com...
> Karl,
> Happen to have the name of that method?
>

Set page stylesheet in code-behind?

Let's say we want to change the page style each day:

<HEAD>
..
..
..
<style type="text/css" media="all">@dotnet.itags.org.import url( TuesdayStyles.css );
</style>
</HEAD
Is it possible to do this in *code-behind* ? Can you write the <STYLE>
directive into the <HEAD></HEAD> section of the page?
Thanks
Liamin 2.0 it's easier...they have a method just for this.

in 1.1, you can plunk a literal down and use Literal.Text = "aaaaa"

Karl

--
MY ASP.Net tutorials
http://www.openmymind.net/

"Liam" <Liam@.zzzz.net> wrote in message
news:ORITw$TFGHA.3100@.tk2msftngp13.phx.gbl...
> Let's say we want to change the page style each day:
> <HEAD>
> .
> .
> .
> <style type="text/css" media="all">@.import url( TuesdayStyles.css );
> </style>
> </HEAD>
> Is it possible to do this in *code-behind* ? Can you write the <STYLE>
> directive into the <HEAD></HEAD> section of the page?
> Thanks
> Liam
Karl,

Happen to have the name of that method?
In 2.0? It's under Page.Header.StyleSheet

Page.Header is great in 2.0...check it out:
http://msdn2.microsoft.com/en-us/li...ad_members.aspx

Karl
--
MY ASP.Net tutorials
http://www.openmymind.net/

"The Colonel" <colonelangus@.budweiser.com> wrote in message
news:1136832866.985107.80350@.o13g2000cwo.googlegro ups.com...
> Karl,
> Happen to have the name of that method?