 |
| 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
|
|
|
|

June 13th, 2005, 10:57 AM
|
|
Authorized User
|
|
Join Date: Jun 2005
Posts: 17
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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
|
|

June 13th, 2005, 01:43 PM
|
 |
Friend of Wrox
|
|
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
|
|
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
|
|

June 15th, 2005, 10:43 AM
|
|
Authorized User
|
|
Join Date: Jun 2005
Posts: 17
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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
|
|

June 15th, 2005, 01:08 PM
|
 |
Friend of Wrox
|
|
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
|
|
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
|
|

June 16th, 2005, 07:39 AM
|
|
Authorized User
|
|
Join Date: Jun 2005
Posts: 17
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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
|
|

June 16th, 2005, 10:01 AM
|
 |
Friend of Wrox
|
|
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
|
|
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
|
|

June 16th, 2005, 10:59 AM
|
|
Authorized User
|
|
Join Date: Jun 2005
Posts: 17
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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
|
|

June 17th, 2005, 07:55 AM
|
 |
Friend of Wrox
|
|
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
|
|
My bad, I overlooked the row collection:
DataSet2.Tables["ColourScheme"].Rows[0]["PageBackground"].ToString();
- Peter
|
|
 |