Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to use Single Quotes in Eval Format String
    primarykey
    data
    text
    <p>I've got a Repeater and its SqlDatasource nested inside a Gridview TemplatedField.<br> The Repeater's datasource SelectCommand is set using the FormatString of an Eval from the Gridview.<br> The SelectCommand has a WHERE clause which is to compare a string.<br> Because I have already used the single and double quotes, I am having trouble delimiting the string in the SQL WHERE clause.</p> <p><strong>How do I add single quotes inside an Eval FormatString?</strong> </p> <p>I have tried using '<a href="http://forums.asp.net/p/1116668/1732706.aspx#1732706" rel="noreferrer">Replace</a>'.<br> I have tried using '<a href="http://www.firstobject.com/dn_markspecialchar.htm" rel="noreferrer">Special Characters</a>' (... WHERE StringField = &apos;{0}&apos; ...) </p> <p>No luck so far. I appreciate any help you may be able to offer. </p> <pre><code>&lt;asp:GridView ID="GridView1" runat="server" DataSourceID="DataSource1" DataKeyNames="Foo" AutoGenerateColumns="False" AllowSorting="true" &gt; &lt;Columns&gt; &lt;asp:BoundField DataField="Foo" HeaderText="Foo" SortExpression="Foo" /&gt; &lt;asp:BoundField DataField="Bar" HeaderText="Bar" SortExpression="Bar" /&gt; &lt;asp:TemplateField&gt; &lt;ItemTemplate&gt; &lt;asp:Repeater ID="Repeater1" runat="server" DataSourceID="DataSourceNested"&gt; &lt;ItemTemplate&gt; &lt;asp:Label ID="Label1" runat="server" Text='&lt;%# Eval("Blah") %&gt;'&gt;&lt;/asp:Label&gt; &lt;/ItemTemplate&gt; &lt;/asp:Repeater&gt; &lt;asp:SqlDataSource ID="DataSourceNested" runat="server" DataFile="~/App_Data/DatabaseName" SelectCommand='&lt;%# Eval("Bar", "SELECT Blah FROM TableName WHERE (StringField = {0})") %&gt;' &gt; &lt;/asp:SqlDataSource&gt; &lt;/ItemTemplate&gt; &lt;/asp:TemplateField&gt; &lt;/Columns&gt; &lt;/asp:GridView&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload