views:

8

answers:

1

Hello,

Why does this work:

ListItem item = new ListItem();
string value = lstAvailExtPropsToFilter.SelectedItem.Text +" = "+ txtExtPropToFilter.Text;
string text = lstAvailExtPropsToFilter.SelectedItem.Text + " = " + txtExtPropToFilter.Text;
item.Text = text;
item.Value = value;
lstExtPropsToFilter.Items.Add(item);

But not this:

ListItem item = new ListItem();
string value = string.Format("<key>{0}</key><value>{1}</value>", lstAvailExtPropsToFilter.SelectedItem.Text, txtExtPropToFilter.Text);
string text = lstAvailExtPropsToFilter.SelectedItem.Text + " = " + txtExtPropToFilter.Text;
item.Text = text;
item.Value = value;
lstExtPropsToFilter.Items.Add(item);
+2  A: 

You would have to escape the string so it works in HTML. Try Server.HTMLEncode.

Server.HTMLEncode("<key>{0}</key><value>{1}</value>")

Then when you need to pull the value you, use Server.HTMLDecode.

Shawn Steward
Beautiful! Thanks for the prompt response! BTW, it's "HtmlEncode" not "HTMLEncode".
mcass20