Double Quote (") in String

Discussion in 'ASP .Net' started by Kali, Jan 8, 2010.

  1. Kali

    Kali Guest

    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?
    Kali, Jan 8, 2010
    #1
    1. Advertising

  2. Kali

    Scott M. Guest

    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" <> wrote in message
    news:uCp5ni$...
    >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., Jan 8, 2010
    #2
    1. Advertising

  3. "Kali" <> wrote in
    news:uCp5ni$:

    > 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! |
    *******************************************
    Gregory A. Beamer, Jan 8, 2010
    #3
  4. Kali

    Vijay Guest

    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" <> wrote in message
    news:uCp5ni$...
    > 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?
    >
    >
    Vijay, Jan 9, 2010
    #4
  5. Kali

    Scott M. Guest

    Of course, that assumes you are using C#.

    -Scott


    "Vijay" <> wrote in message
    news:...
    > 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" <> wrote in message
    > news:uCp5ni$...
    >> 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., Jan 9, 2010
    #5
  6. Kali

    Kali Guest

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

    "Vijay" <> wrote in message
    news:...
    > 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" <> wrote in message
    > news:uCp5ni$...
    >> 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, Jan 9, 2010
    #6
  7. Kali

    Scott M. Guest

    "Kali" <> wrote in message
    news:...
    > 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
    Scott M., Jan 9, 2010
    #7
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Sydex
    Replies:
    12
    Views:
    6,454
    Victor Bazarov
    Feb 17, 2005
  2. Replies:
    3
    Views:
    13,151
  3. Eric Layman
    Replies:
    3
    Views:
    616
    Rad [Visual C# MVP]
    Apr 14, 2007
  4. Evan
    Replies:
    3
    Views:
    506
    Marc 'BlackJack' Rintsch
    Nov 4, 2008
  5. vikrant
    Replies:
    8
    Views:
    349
    vikrant
    May 17, 2007
Loading...

Share This Page