我的gridview中没有显示任何内容

时间:2011-04-02 12:57:05

标签: c# asp.net mysql sql html

当我尝试这个时,我的gridview中没有显示任何内容:

   protected void Button2_Click(object sender, EventArgs e)
    {
        string FirstName = TextBox2.Text;
        SqlDataSource1.SelectCommand = "SELECT FirstName, SecondName FROM User WHERE FirstName LIKE '%" + FirstName + "%'";

        GridView1.DataBind();
    }
}

我的sqldatasource绑定到odbc连接字符串,因此我可以连接到mysql数据库 ASP:

<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder2" Runat="Server">
    <asp:SqlDataSource ID="SqlDataSource1" runat="server" 
        ConnectionString="<%$ ConnectionStrings:ODBCDataConnectionString %>" 
        ProviderName="<%$ ConnectionStrings:ODBCDataConnectionString.ProviderName %>" 
        SelectCommand="SELECT FirstName, SecondName FROM User WHERE FirstName LIKE '%' + @qsFirstName + '%'">
        <SelectParameters>
        <asp:QueryStringParameter Name="qsFirstName" QueryStringField="firstname" />
        </SelectParameters>
    </asp:SqlDataSource>
    <asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
    <asp:Button ID="Button2" runat="server" onclick="Button2_Click" Text="Button" />
    <asp:GridView ID="GridView1" runat="server" DataSourceID="SqlDataSource1" 
        EnableModelValidation="True">
    </asp:GridView>
</asp:Content>

1 个答案:

答案 0 :(得分:0)

构建后,select命令的值是多少?

SqlDataSource1.SelectCommand =“SELECT FirstName,SecondName FROM User WHERE FirstName LIKE'%”+ FirstName +“%'”;

FirstName是否有任何尾随空格?