GridView is empty
<p>I have a page (which has a MasterPage) with a GridView and an SqlDataSource. If I set SelectCommand in the markup, the GridView is displayed fine. But if I generate the same SelectCommand dynamically, the GridView is empty. And I know that the query is executed.
What can be the reason for it?
Thanks.</p>

<pre><code>&lt;asp:SqlDataSource ID="UserSqlDataSource" runat="server" 
    ConnectionString="&lt;%$ ConnectionStrings:BookList %&gt;" DataSourceMode="DataSet" 
    ProviderName="&lt;%$ ConnectionStrings:BookList.ProviderName %&gt;" &gt;
&lt;/asp:SqlDataSource&gt;  

        &lt;asp:GridView ID="grdUsers" runat="server" AllowPaging="True" ShowHeader="false" ShowFooter="true" 
            AutoGenerateColumns="false"
            Width="1480px" Height="100%" PageSize="50" DataSourceID="UserSqlDataSource" DataKeyNames="ID"&gt;
                &lt;AlternatingRowStyle CssClass="alternatingrowstyle" /&gt;
                &lt;Columns&gt;
                     &lt;asp:TemplateField HeaderText="User Name" SortExpression="Name"&gt;
                        &lt;ItemTemplate&gt;
                            &lt;asp:Label ID="lblName" runat="server" Text='&lt;%# Eval("Name") %&gt;'&gt;&lt;/asp:Label&gt;
                        &lt;/ItemTemplate&gt;
                    &lt;/asp:TemplateField&gt;
                    &lt;asp:TemplateField HeaderText="Last Name" SortExpression="LastName"&gt;
                        &lt;ItemTemplate&gt;
                            &lt;asp:Label ID="lblLastName" runat="server" Text='&lt;%# Eval("LastName") %&gt;'&gt;&lt;/asp:Label&gt;
                        &lt;/ItemTemplate&gt;
                    &lt;/asp:TemplateField&gt;                        
                    &lt;asp:TemplateField HeaderText="First Name" SortExpression="FirstName"&gt;
                        &lt;ItemTemplate&gt;
                            &lt;asp:Label ID="lblFirstName" runat="server" Text='&lt;%# Eval("FirstName") %&gt;'&gt;&lt;/asp:Label&gt;
                        &lt;/ItemTemplate&gt;
                    &lt;/asp:TemplateField&gt;
                    &lt;asp:TemplateField HeaderText="Email" SortExpression="Email"&gt;
                        &lt;ItemTemplate&gt;
                            &lt;asp:Label ID="lblEmail" runat="server" Text='&lt;%# Eval("Email") %&gt;'&gt;&lt;/asp:Label&gt;
                        &lt;/ItemTemplate&gt;
                    &lt;/asp:TemplateField&gt;                        

                &lt;/Columns&gt;

            &lt;/asp:GridView&gt;

protected void Page_Load(object sender, EventArgs e)
{
    if (!IsPostBack)
    {
        BindUsers();
    }
}

protected void BindUsers()
{
    string strSelectClause = 
        @"SELECT ID, Name, FirstName, LastName, EMail, 
      FROM User WHERE Name NOT IN ('*All', 'Admin', 'TPS') ";

    string strQuery = strSelectClause + GenerateWhereClause() + " ORDER BY Name;";

    SqlDataSource UserSqlDataSource = GetControl(this, "UserSqlDataSource") as SqlDataSource;
    UserSqlDataSource.SelectCommand = strQuery;
    grdUsers.DataBind();
}
</code></pre>
