我有以下Gridview,我试图传递搜索参数,以基于该搜索更新结果 -
<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>
但是我似乎无法让SQL语句接受用户输入的TextBox1文本,我该如何解决?
答案 0 :(得分:1)
您必须在后面的代码中执行此操作。
SqlDataSource1.SelectCommand = "SELECT * FROM [table] WHERE BODYTEXT LIKE='"+TextBox1.Text;
单击搜索按钮即可执行此操作。