Wrox Programmer Forums
Go Back   Wrox Programmer Forums > .NET > Other .NET > General .NET
|
General .NET For general discussion of MICROSOFT .NET topics that don't fall within any of the other .NET forum subcategories or .NET language forums.  If your question is specific to a language (C# or Visual Basic) or type of application (Windows Forms or ASP.Net) try an applicable forum category. ** PLEASE BE SPECIFIC WITH YOUR QUESTION ** When posting here, provide details regarding the Microsoft .NET language you are using and/or what type of application (Windows/Web Forms, etc) you are working in, if applicable to the question. This will help others answer the question without having to ask.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the General .NET section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old June 13th, 2005, 10:57 AM
Authorized User
 
Join Date: Jun 2005
Posts: 17
Thanks: 0
Thanked 0 Times in 0 Posts
Default Linking body, bgcolor"<%%>" to database

Hi all!

I am just starting out in ASP.Net using C# and I am loving it. My problem is that my client wants to be able to change the background colour of the page by adjusting values in database table.

I have already linked my repeater table colours to the database table:
bgcolor='<%#DataBinder.Eval(Container.DataItem, "TableHeader") %>' that was easy enough. So how is this done without using a web control in the html code.

This is where I need the database to link "<body bgcolor="<%%>">"
I know this is quite simple, but I have searched high and low and cant find any info on it.

Any help will be appreciated
Thanks
Brett
 
Old June 13th, 2005, 01:43 PM
planoie's Avatar
Friend of Wrox
 
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

My recommendation is to make your body tag runat="server", then you can adjust whatever properties you wish. You'll need to define the body tag in the code-behind as an HtmlGenericControl:

<body runat="server" id="tagBody">
...
Protected tagBody As HtmlGenericControl
...
tagBody.Attributes("bgcolor") = "#FF0000"

-Peter
 
Old June 15th, 2005, 10:43 AM
Authorized User
 
Join Date: Jun 2005
Posts: 17
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks for the prompt reply Peter! I struggled with it for a while, but then when I changed the tagBody.Attributes("bgcolor") to tagBody.Attributes["bgcolor"] it worked! So how do I link this to a field in the database. for example [ColourScheme].[Background]

Brett

 
Old June 15th, 2005, 01:08 PM
planoie's Avatar
Friend of Wrox
 
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

You need to select the data from the database and assign it to that attribute value instead of assigning a literal string value. Presumably you have already gotten database retrievals working in order to work with the repeate you described in the earlier post.

-Peter
 
Old June 16th, 2005, 07:39 AM
Authorized User
 
Join Date: Jun 2005
Posts: 17
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi Peter

I am having trouble assigning that attribute, when I use the following code,

tagBody.Attributes["bgcolor"]= DataSet2.Tables["ColourScheme"].ToString();

it just displays: <BODY bgcolor="Colourscheme" > it seems to be just reading whats in the parethesis and displaying that.

Your help is appriciated, I am really learning a lot.

Thanks
Brett

 
Old June 16th, 2005, 10:01 AM
planoie's Avatar
Friend of Wrox
 
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

That's because the ToString method of a datatable is the name of the table.

You need to be more specific with your data reference and provide a column:

DataSet2.Tables["ColourScheme"]["ColorChoiceColumn"].ToString();

-Peter
 
Old June 16th, 2005, 10:59 AM
Authorized User
 
Join Date: Jun 2005
Posts: 17
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I added the column name:

tagBody.Attributes["bgcolor"] = DataSet2.Tables["ColourScheme"].["PageBackground"].ToString();

But I recieved this error message:

Compiler Error Message: CS1001: Identifier expected

Brett

 
Old June 17th, 2005, 07:55 AM
planoie's Avatar
Friend of Wrox
 
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

My bad, I overlooked the row collection:

DataSet2.Tables["ColourScheme"].Rows[0]["PageBackground"].ToString();

-Peter





Similar Threads
Thread Thread Starter Forum Replies Last Post
Extracting text between <body> tags sumedha HTML Code Clinic 2 June 29th, 2005 02:37 PM
<style> tags in a <body> vs. <div> bcat BOOK: Beginning CSS: Cascading Style Sheets for Web Design ISBN: 978-0-7645-7642-3 1 March 27th, 2005 08:50 AM
Response.Write output is of <body></body> yoord BOOK: Beginning ASP.NET 1.0 0 October 13th, 2004 07:06 AM
<marquee><b>About CHAT App. in PHP4</b></marquee> Ramkrishna PHP How-To 1 September 11th, 2004 07:01 AM
functions in <HEAD> vs <BODY> John K. King Javascript 4 April 5th, 2004 08:53 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.