Showing posts with label single. Show all posts
Showing posts with label single. 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 dropdownlist from static data

I have a dropdownbox object:

<asp:DropDownList ID="ddlQuestionType" runat="server">
<asp:ListItem Value="MS" Text="Multiple Single" />
<asp:ListItem Value="MM" Text="Multiple Multiple" />
<asp:ListItem Value="TF" Text="True/False" />
</asp:DropDownList
The values and text are static. I am reading from a table:

Select QuestionType from myTable where id = 10

and QuestionType will either be "MS", "MM" or "TF".

How do I bind the data to this object?

With a Label it would be something like:

<asp:label id="Question" Text='<%# DataBinder.Eval(Container.DataItem,
"QuestionUnique") %>' runat="server" /
Thanks,

Tom.Databinding from a SQL table is easy, you should be able to find many
examples out there.

You need to know more about this database you are querying though.

1.) Is it a MS SQL server or is it another type?
2.) Do you have to login to the server, or does it accept inherited
credentials?
3.) Do you have the database name you are connecting to?
"Chad Devine" <surr3al@.gmail.com> wrote in message
news:1104870094.287340.59580@.z14g2000cwz.googlegro ups.com...
> Databinding from a SQL table is easy, you should be able to find many
> examples out there.
> You need to know more about this database you are querying though.
> 1.) Is it a MS SQL server or is it another type?
> 2.) Do you have to login to the server, or does it accept inherited
> credentials?
> 3.) Do you have the database name you are connecting to?

Actuall, no.

How I get the data is not the issue here.

I can get the data fine. It will always be either MM, MS or TF. I also
have no problem binding to a textbox, label, datagrid etc.

<%# DataBinder.Eval(Container.DataItem, "QuestionUnique") %
I want to do the same type of thing here where my selected item will display
based on the data returned.

Somehow, I need to do something like:

questionType.SelectedItem.value = <%# DataBinder.Eval(Container.DataItem,
"QuestionType") %
So that the value will show correctly in the dropdownbox.

Thanks,

Tom
Oh so you want the dropdownlist to change the currently selected item
to the one that's in the table? I have tried doing that in the past but
haven't had any luck, I'm only intermediate in skill with asp.net so
hopefully someone else can provide a solution for you.

It may require you to go as far as using a custom control for what you
are trying to do.
"Chad Devine" <surr3al@.gmail.com> wrote in message
news:1104963175.704187.310580@.c13g2000cwb.googlegr oups.com...
> Oh so you want the dropdownlist to change the currently selected item
> to the one that's in the table? I have tried doing that in the past but
> haven't had any luck, I'm only intermediate in skill with asp.net so
> hopefully someone else can provide a solution for you.
> It may require you to go as far as using a custom control for what you
> are trying to do.

I hope not.

I assume that other people must do this. The problem with other examples,
is that they assume you want to populate the list with the results from your
table. But if you are looking at data that was already input and want to
allow the user to make a change to that data later, you would set the
dropdown to the data they had already chosen and allow them to choose
something else from the dropdown.

Thanks,

Tom.
Yeah, I completely agree with you and what you say makes sense.

Many suggest that doing a
If not ispostback then
DropDownList.DataBind()
End If

So that the databind doesn't happen unless the person refreshes the
page, that way it keeps whatever the user selected, however in the case
of a table, when the user hits submit it refreshes the whole page so
that method doesn't work in this case. I really wish I could help you
in this, but I can't seem to find a property of the dropdownlist that
allows you to change the current selected item. You only seem to get
that chance right in the beginning when you define what options and
values to go into the list.
Look here, I think this person is doing what you want to do:
http://groups-beta.google.com/group...557b5a7b406fa52
I just figured out your answer... I did it for myself, but with
autopostback it presents a little problem, when calling it in the
Page_Load sub because it won't let you change the current selected
item, as it keeps trying to select the previous one posted for some
reason.

Anyway, I put it in the sub Page_PreRender and it worked just fine.

Here's the code:
Sub Page_PreRender
dropListOptions.SelectedValue = intPageNumber
End Sub

<asp:DropDownList
ID="dropListOptions"
AutoPostBack="True"
OnSelectedIndexChanged="dropListOptions_SelectedIndexChanged"
font-size="10"
Runat="Server" >
<asp:ListItem id="Default" Text="Default" Value="25" />
<asp:ListItem Text="50" Value="50" />
<asp:ListItem Text="75" Value="75" />
<asp:ListItem Text="100" Value="100" />
<asp:ListItem Text="150" Value="150" />
<asp:ListItem Text="200" Value="200" />
</asp:DropDownList
Hope this helps!
Another update, I found that only works for Value properties, so if
your databinding this, this would be a problem... and then we're back
to square one.
Ignore the above post, I made an error in my code because I was writing
it too fast.

Anyway, this solution works fine, and it's all in sub code which I
think is better... that way you don't have to scroll between variables
in your html and your subs, it's all in one place. Again, I hope this
helps.
"Chad Devine" <surr3al@.gmail.com> wrote in message
news:1105051197.174515.91240@.f14g2000cwb.googlegro ups.com...
> Ignore the above post, I made an error in my code because I was writing
> it too fast.
> Anyway, this solution works fine, and it's all in sub code which I
> think is better... that way you don't have to scroll between variables
> in your html and your subs, it's all in one place. Again, I hope this
> helps.

I'll look at it and see how it works and let you know.

Thanks for the help,

Tom

Set dropdownlist from static data

I have a dropdownbox object:
<asp:DropDownList ID="ddlQuestionType" runat="server">
<asp:ListItem Value="MS" Text="Multiple Single" />
<asp:ListItem Value="MM" Text="Multiple Multiple" />
<asp:ListItem Value="TF" Text="True/False" />
</asp:DropDownList>
The values and text are static. I am reading from a table:
Select QuestionType from myTable where id = 10
and QuestionType will either be "MS", "MM" or "TF".
How do I bind the data to this object?
With a Label it would be something like:
<asp:label id="Question" Text='<%# DataBinder.Eval(Container.DataItem,
"QuestionUnique") %>' runat="server" />
Thanks,
Tom.Databinding from a SQL table is easy, you should be able to find many
examples out there.
You need to know more about this database you are querying though.
1.) Is it a MS SQL server or is it another type?
2.) Do you have to login to the server, or does it accept inherited
credentials?
3.) Do you have the database name you are connecting to?
"Chad Devine" <surr3al@.gmail.com> wrote in message
news:1104870094.287340.59580@.z14g2000cwz.googlegroups.com...
> Databinding from a SQL table is easy, you should be able to find many
> examples out there.
> You need to know more about this database you are querying though.
> 1.) Is it a MS SQL server or is it another type?
> 2.) Do you have to login to the server, or does it accept inherited
> credentials?
> 3.) Do you have the database name you are connecting to?
>
Actuall, no.
How I get the data is not the issue here.
I can get the data fine. It will always be either MM, MS or TF. I also
have no problem binding to a textbox, label, datagrid etc.
<%# DataBinder.Eval(Container.DataItem, "QuestionUnique") %>
I want to do the same type of thing here where my selected item will display
based on the data returned.
Somehow, I need to do something like:
questionType.SelectedItem.value = <%# DataBinder.Eval(Container.DataItem,
"QuestionType") %>
So that the value will show correctly in the dropdownbox.
Thanks,
Tom
Oh so you want the dropdownlist to change the currently selected item
to the one that's in the table? I have tried doing that in the past but
haven't had any luck, I'm only intermediate in skill with asp.net so
hopefully someone else can provide a solution for you.
It may require you to go as far as using a custom control for what you
are trying to do.
"Chad Devine" <surr3al@.gmail.com> wrote in message
news:1104963175.704187.310580@.c13g2000cwb.googlegroups.com...
> Oh so you want the dropdownlist to change the currently selected item
> to the one that's in the table? I have tried doing that in the past but
> haven't had any luck, I'm only intermediate in skill with asp.net so
> hopefully someone else can provide a solution for you.
> It may require you to go as far as using a custom control for what you
> are trying to do.
>
I hope not.
I assume that other people must do this. The problem with other examples,
is that they assume you want to populate the list with the results from your
table. But if you are looking at data that was already input and want to
allow the user to make a change to that data later, you would set the
dropdown to the data they had already chosen and allow them to choose
something else from the dropdown.
Thanks,
Tom.
Yeah, I completely agree with you and what you say makes sense.
Many suggest that doing a
If not ispostback then
DropDownList.DataBind()
End If
So that the databind doesn't happen unless the person refreshes the
page, that way it keeps whatever the user selected, however in the case
of a table, when the user hits submit it refreshes the whole page so
that method doesn't work in this case. I really wish I could help you
in this, but I can't seem to find a property of the dropdownlist that
allows you to change the current selected item. You only seem to get
that chance right in the beginning when you define what options and
values to go into the list.
Look here, I think this person is doing what you want to do:
http://groups-beta.google.com/group...557b5a7b406fa52
I just figured out your answer... I did it for myself, but with
autopostback it presents a little problem, when calling it in the
Page_Load sub because it won't let you change the current selected
item, as it keeps trying to select the previous one posted for some
reason.
Anyway, I put it in the sub Page_PreRender and it worked just fine.
Here's the code:
Sub Page_PreRender
dropListOptions.SelectedValue = intPageNumber
End Sub
<asp:DropDownList
ID="dropListOptions"
AutoPostBack="True"
OnSelectedIndexChanged="dropListOptions_SelectedIndexChanged"
font-size="10"
Runat="Server" >
<asp:ListItem id="Default" Text="Default" Value="25" />
<asp:ListItem Text="50" Value="50" />
<asp:ListItem Text="75" Value="75" />
<asp:ListItem Text="100" Value="100" />
<asp:ListItem Text="150" Value="150" />
<asp:ListItem Text="200" Value="200" />
</asp:DropDownList>
Hope this helps!
Another update, I found that only works for Value properties, so if
your databinding this, this would be a problem... and then we're back
to square one.
Ignore the above post, I made an error in my code because I was writing
it too fast.
Anyway, this solution works fine, and it's all in sub code which I
think is better... that way you don't have to scroll between variables
in your html and your subs, it's all in one place. Again, I hope this
helps.

Thursday, March 22, 2012

Set formatting (color) on a literal or label

We have a status message we display that can be good news (in green) or bad
news (in red). Is there a way to do this for a single literal or label? Or do
we need to have two, one set to green and one to red and just set one to a
text string and the other to ""?

--
thanks - dave
david_at_windward_dot_net
http://www.windwardreports.comDim GoodNews as Boolean
....
If GoodNews Then
MessageLabel.Font.Color = Color.Green
Else
MessageLabel.Font.Color = Color.Red
End If

"David Thielen" <thielen@.nospam.nospam> wrote in message
news:5D81CB86-10F8-471F-A5E7-00E187DABF4B@.microsoft.com...
> We have a status message we display that can be good news (in green) or
> bad
> news (in red). Is there a way to do this for a single literal or label? Or
> do
> we need to have two, one set to green and one to red and just set one to a
> text string and the other to ""?
> --
> thanks - dave
> david_at_windward_dot_net
> http://www.windwardreports.com
If you do it using a Literal you can set the Text property to the complete
markup e.g.
If GoodNews Then
Literal1.Text = "<span class='greencolorCss'>this is the status
for good news </span>"
Else
Literal1.Text = "<span class='redcolorCss'>this is the status
for bad news </span>"
End If

If you do it using a Label you might write:
If GoodNews Then
Label1.CssClass = "greencolorCss"
Label1.Text = "This is the status for good news"

Else
Label1.CssClass = "redcolorCss"
Label1.Text = "This is the status for bad news"
End If
--
HTH,
Phillip Williams
http://www.societopia.net
http://www.webswapp.com

"David Thielen" wrote:

> We have a status message we display that can be good news (in green) or bad
> news (in red). Is there a way to do this for a single literal or label? Or do
> we need to have two, one set to green and one to red and just set one to a
> text string and the other to ""?
> --
> thanks - dave
> david_at_windward_dot_net
> http://www.windwardreports.com

Tuesday, March 13, 2012

Set Page Breaks When Printing

This is more of an HTML question...I guess.

I am populating an aspx page that has a single label control. The label control is populated with HTML code that is stored in a database. This HTML is code that creates a printable version of an application that customers are filling out. The form does not always fit on a single page.

How can I set markers in the HTML that indicate where one page ends and the next begins?

look at CSS... I belive the tag is "page-break: after;" and "page-break: before;"


Ha! Thank you!

I found an online resource that was helpful thanks to your suggestion:http://www.javascriptkit.com/dhtmltutors/pagebreak.shtml