我试图使用文本框作为 gridview 的过滤器并最终编写了以下代码:
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
Try
SqlDataSource1.ConnectionString = "connection string goes here"
SqlDataSource1.SelectCommand = "SELECT * FROM TABLE WHERE area LIKE '" + TextBox1.Text + "%'"
'GridView1.DataSource = SqlDataSource1.SelectCommand
SqlDataSource1.DataBind()
GridView1.DataBind()
Catch ex As Exception
MsgBox(ex.ToString)
End Try
End Sub
有用。但是我觉得它太简单和不安全。您能否告诉我应该如何以更“专业”(真实)的方式完成?