求教ASP.NET(c#)动态操作gridview显示数据库内容

2024-12-27 08:55:43
推荐回答(2个)
回答1:

把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()

回答2:

QQ留下或加我ID