把sql语句写进SqlDataSource里,下面给VB.net的例子
触发button的点击事件,执行如下代码
Dim sql As String
sql = "select * from tableA where id <>''"
If Not textbox1.text.trim = "" Then
sql = sql & " and colB = '" & textbox1.Text.trim & "'"
End If
sql = sql & " order by id desc"
SqlDataSource7.SelectCommand = sql
GridView1.DataSourceID = "SqlDataSource7"
GridView1.DataBind()
QQ留下或加我ID