Hi nothing is being displayed in my gridview when i try this:
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();
}
}
my sqldatasource is bound to a odbc connection string so I can connect to a mysql database 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 Fi开发者_StackOverflow社区rstName 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>
What is the value of the select command after you build it?
SqlDataSource1.SelectCommand = "SELECT FirstName, SecondName FROM User WHERE FirstName LIKE '%" + FirstName + "%'";
Does FirstName have any trailing spaces?
精彩评论