Wednesday, November 21, 2007

Image references in your CSS not showing?

If you have a background image in your CSS called like this,

background-image: url(/images/background.gif);

...and when you run your Web application the background isn't showing up it could be a problem with your 'Virtual Path' setting. To fix this, click on the main project path in your Solution Explorer, at the very top, change the 'Virtual Path' property to read "/"

Thursday, November 15, 2007

Editing Meta Tags From Code Behind

Dynamically change the content of meta tags from the code behind. This allows you to feed the meta tags with content from a database or other dynamic content.

In your aspx source code do:

<meta id="metaDescription" name="description" content="" runat="server" />

In your aspx code behind do:

metaDescription.Content = "Description goes here"

The key is the runat="server" and the unique id within the meta tag. This allows you to "see" it in your code behind and manipulate it before sending it to the browser.

Thursday, November 8, 2007

Adding a value to a dropdownlist after *.DataBind()

If you have a DropDownList component that is getting fed via a query or an ObjectDataSource, you can insert items into the list in such a way:

DropDownList.DataBind()
DropDownList.Items.Insert(<listLocation>, New ListItem("<name>", <value>))

Where <listLocation> is an integer that tells where to put the item within the DropDownList, <name> being the name that's displayed within the DropDownList, and <value> being the value associated with that item. Example:

DropDownList.DataBind()
DropDownList.Items.Insert(0, New ListItem("Select All", 0))

ObjectDataSource SelectParameters

If you have a component being bound from an ObjectDataSource (like a drop-down menu, or a grid view) and you wish to change the value's parameters SelectParameters:

ObjectDataSource.SelectParameters(#).DefaultValue = value
GridView.DataBind()

Where # is which SelectParameter you'd like to change. If there's just one SelectParamter, default is 0. Then reference your object that uses that datasource, in this case a GridView, to rebind.