Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   ASP .Net (http://www.velocityreviews.com/forums/f29-asp-net.html)
-   -   Double Quote (") in String (http://www.velocityreviews.com/forums/t711062-double-quote-in-string.html)

Kali 01-08-2010 12:22 AM

Double Quote (") in String
 
I need to use a double quote (") in the value and text of a listitem. How
can this be done without having to use " ?
For example, <asp:listitem value="2" x 4"" text="2" x 4""/> doest work. I
don't want to use &quot;, is this possible with a @ or something?



Scott M. 01-08-2010 12:47 AM

Re: Double Quote (") in String
 
Well, &quot; is really the correct way to do this. But, there are a few
other options:

First, you only need the text and value attributes of a ListItem when you
enter their values in the Properties Window of VS while in source code view,
but even then you can use single quotes for the property boudaries, as in:

<asp:DropDownList ID="DropDownList1" runat="server">
<asp:ListItem Text='3"' Value='3"'>2"</asp:ListItem>
</asp:DropDownList>

This allows you to use the double quotes in the property value, without them
screwing up the reading of the markup.

But, you don't even have to write the code that way to achieve the same
result. If you were to use the SmartTask option in the Designer, and edit
the listitems that way, you'll see the code gets written like this:

<asp:DropDownList ID="DropDownList1" runat="server">
<asp:ListItem>2&quot;</asp:ListItem>
</asp:DropDownList>

But, because the text/value isn't being stored in a property, per se, you
can replace the &quot; with ", as in:

<asp:DropDownList ID="DropDownList1" runat="server">
<asp:ListItem>2"</asp:ListItem>
</asp:DropDownList>

-Scott


"Kali" <noemail@address.com> wrote in message
news:uCp5ni$jKHA.1652@TK2MSFTNGP05.phx.gbl...
>I need to use a double quote (") in the value and text of a listitem. How
>can this be done without having to use &quot; ?
> For example, <asp:listitem value="2" x 4"" text="2" x 4""/> doest work. I
> don't want to use &quot;, is this possible with a @ or something?
>
>




Gregory A. Beamer 01-08-2010 03:42 PM

Re: Double Quote (") in String
 
"Kali" <noemail@address.com> wrote in
news:uCp5ni$jKHA.1652@TK2MSFTNGP05.phx.gbl:

> I need to use a double quote (") in the value and text of a listitem.
> How can this be done without having to use &quot; ?
> For example, <asp:listitem value="2" x 4"" text="2" x 4""/> doest
> work. I don't want to use &quot;, is this possible with a @ or
> something?
>


There is no way, in XML, to escape in a tag. The ASPX page is an XHTML
document, so no.

You can bind the list item to strings with quotes, however. You can also
use two single quotes for inches or switch to single quotes to set off the
string (at least I think that will work), but binding is a better option
than hard coding list items.

Peace and Grace,

--
Gregory A. Beamer (MVP)

Twitter: @gbworld
Blog: http://gregorybeamer.spaces.live.com

*******************************************
| Think outside the box! |
*******************************************

Vijay 01-09-2010 04:48 AM

Re: Double Quote (") in String
 
Another options is you can initialize the value in code. Here you can use
\" for double quotes.

protected void DropDownList1_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
DropDownList1.Items.Add("2\"");
DropDownList1.Items.Add("3\"");
}
}


"Kali" <noemail@address.com> wrote in message
news:uCp5ni$jKHA.1652@TK2MSFTNGP05.phx.gbl...
> I need to use a double quote (") in the value and text of a listitem. How
> can this be done without having to use &quot; ?
> For example, <asp:listitem value="2" x 4"" text="2" x 4""/> doest work. I
> don't want to use &quot;, is this possible with a @ or something?
>
>


Scott M. 01-09-2010 06:37 AM

Re: Double Quote (") in String
 
Of course, that assumes you are using C#.

-Scott


"Vijay" <vijaychandar1989@gmail.com> wrote in message
news:CB0AFE49-0FC1-4AF2-B9FF-A4A9FFD7E617@microsoft.com...
> Another options is you can initialize the value in code. Here you can use
> \" for double quotes.
>
> protected void DropDownList1_Load(object sender, EventArgs e)
> {
> if (!IsPostBack)
> {
> DropDownList1.Items.Add("2\"");
> DropDownList1.Items.Add("3\"");
> }
> }
>
>
> "Kali" <noemail@address.com> wrote in message
> news:uCp5ni$jKHA.1652@TK2MSFTNGP05.phx.gbl...
>> I need to use a double quote (") in the value and text of a listitem.
>> How can this be done without having to use &quot; ?
>> For example, <asp:listitem value="2" x 4"" text="2" x 4""/> doest work.
>> I don't want to use &quot;, is this possible with a @ or something?
>>
>>




Kali 01-09-2010 05:12 PM

Re: Double Quote (") in String
 
Thanks. I am using C#, however, not inserting the items in code. Can
<asp:listitem value="2\"" be used?

"Vijay" <vijaychandar1989@gmail.com> wrote in message
news:CB0AFE49-0FC1-4AF2-B9FF-A4A9FFD7E617@microsoft.com...
> Another options is you can initialize the value in code. Here you can use
> \" for double quotes.
>
> protected void DropDownList1_Load(object sender, EventArgs e)
> {
> if (!IsPostBack)
> {
> DropDownList1.Items.Add("2\"");
> DropDownList1.Items.Add("3\"");
> }
> }
>
>
> "Kali" <noemail@address.com> wrote in message
> news:uCp5ni$jKHA.1652@TK2MSFTNGP05.phx.gbl...
>> I need to use a double quote (") in the value and text of a listitem.
>> How can this be done without having to use &quot; ?
>> For example, <asp:listitem value="2" x 4"" text="2" x 4""/> doest work.
>> I don't want to use &quot;, is this possible with a @ or something?
>>
>>


Scott M. 01-09-2010 05:20 PM

Re: Double Quote (") in String
 

"Kali" <noemail@address.com> wrote in message
news:eiqMt7UkKHA.1656@TK2MSFTNGP04.phx.gbl...
> Thanks. I am using C#, however, not inserting the items in code. Can
> <asp:listitem value="2\"" be used?


No. The \" escape sequence is just for C# code. As I mentioned though, the
simplest answer for you is to use single quotes to surround your value,
which can then have double quotes as in:

<asp:listitem value='2"'>

-Scott




All times are GMT. The time now is 06:52 PM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.