2012-03-02 12 views
0

私はその検索に基づいて結果を更新するために、検索パラメータを渡すためにしようとしています以下のGridViewのを持っている - 私は得るように見えるカントしかし文字列をTextBox1テキスト

<ContentTemplate> 
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox> 
<asp:Button ID="Button1" runat="server" Text="Search" /> 
<asp:Label ID="Label1" runat="server" Text="Grid not refreshed yet."></asp:Label><br /> 
<asp:Label ID="Label4" runat="server" Text="(Grid Will Referesh after Every Second)"Font-Bold="true"></asp:Label>  
<br /><br /> 
<asp:SqlDataSource ID="SqlDataSource1" runat="server" 
     ConnectionString="<%$ ConnectionStrings:MyDbConn %>" 
     SelectCommand="SELECT * FROM [table] WHERE BODYTEXT LIKE='"+TextBox1.text+"></asp:SqlDataSource> 

    <asp:GridView ID="GridView1" runat="server" AllowPaging="True" 
     BackColor="Black" DataSourceID="SqlDataSource1" Font-Names="Arial Black" 
     Font-Size="Small" ForeColor="White" Height="650px" Width="930px"> 
    </asp:GridView> 
</ContentTemplate> 

ユーザーが入力しているTextBox1テキストを受け入れるSQLステートメント、どのように私はこれを解決できますか?

答えて

1

コード内でこれを行う必要があります。

SqlDataSource1.SelectCommand = "SELECT * FROM [table] WHERE BODYTEXT LIKE='"+TextBox1.Text; 

検索ボタンをクリックすると、これを行うことができます。

関連する問題