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 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
entities... the result set would be something like:
World
Americas
Europe
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 literally
- meaning that I get a list box that is populated with sequences of
... which are visible in the drop down list. If I look at
the HTML that is generated, the <option> tags contain something like
&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
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 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
entities... the result set would be something like:
World
Americas
Europe
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 literally
- meaning that I get a list box that is populated with sequences of
... which are visible in the drop down list. If I look at
the HTML that is generated, the <option> tags contain something like
&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