Rendering HTML returned from a DataSet in an ASP.NET DropDownList

G

Geoff Taylor

Hi everyone,

I'm new to ASP.NET programming and I've made a start with playing with
some pages in Web Matrix. I have some pretty standard c# code which
gets a tree of data from an MSDE database. The tree should populate a
DropDownList control. The idea is that the tree has different levels
of indentation within the drop down list, such as:

World
Americas
Europe
Germany
Netherlands
Amsterdam
United Kingdom ...

In the past with classic ASP, I've controlled the indentation inside a
set of <option> tags by using &nbsp; multiple times to simulate the
indents.

Now, in my Stored Procedure which I have written in the MSDE database,
I generate the indentation directly by replicating a series of &nbsp;
entities... the result set would be something like:

World
&nbsp;Americas
&nbsp;Europe
&nbsp;&nbsp;Germany ...

I use the following c# code to bind the Stored Proc results to the
DropDownList control that I have on the page:

DataSet GetCategoryTree() {
string connectionString = "server=\'(local)\';
trusted_connection=true; database=\'IGotUWant\'";
SqlConnection dbConnection = new
SqlConnection(connectionString);

string sprocName = "igyw_CategoryTree";
SqlCommand dbCommand = new SqlCommand(sprocName,
dbConnection);
dbCommand.CommandType = CommandType.StoredProcedure;

SqlDataAdapter dataAdapter = new SqlDataAdapter();
dataAdapter.SelectCommand = dbCommand;
DataSet dataSet = new DataSet();
dataAdapter.Fill(dataSet);

return dataSet;
}

void Page_Load(object sender, EventArgs e){

if(!Page.IsPostBack)
{
DropDownListCategories.DataTextField = "Category";
DropDownListCategories.DataSource =
GetCategoryTree();
DropDownListCategories.DataValueField =
"pkCategoryItemID";
DropDownListCategories.DataBind();

}

}


And now the problem begins: The DropDownList renders &nbsp; literally
- meaning that I get a list box that is populated with sequences of
&nbsp;&nbsp;... which are visible in the drop down list. If I look at
the HTML that is generated, the <option> tags contain something like
&amp;nbsp; meaning that the that is spit out from the DB is escaped
rather than rendered. Is there then a really easy way to get HTML
returned from the Stored Proc to be rendered inside the list control -
or is there a workaround that anyone knows?

Thanks in advance,
Geoff Taylor
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,989
Messages
2,570,207
Members
46,782
Latest member
ThomasGex

Latest Threads

Top