我想,如果它滿足的條件從GridView
刪除完整的行。從一個GridView刪除完整的行當行滿足條件
在這裏我有
a Description Column from Product table in database
與一個GridView
填充。
我在VB應用程序中設置的sqlcommand
只select the Description which does not contain the String s
。
這裏String s has two keywords "Tomatoes" and "Apple"
。所以Sql Query應該檢索Description column that does not have "Tomatoes" and "Apple"
。
因此Gridview
應通過去除滿足條件的行進行更新。
我對着在去除
Description row in GridView
其中有「西紅柿」和「蘋果」有困難。我試圖填充另一個GridView控件的結果,但它並沒有在網頁中,儘管事實上這一切都是正確的,因爲我已經看到了,我指定的一些斷點值顯示。任何建議或想法?
這裏是我的代碼:
Dim cmd1 = New SqlCommand(" SELECT DISTINCT [Description] FROM [Product] WHERE ([Description] LIKE '%' + @Description + '%')", conn)
cmd1.Parameters.AddWithValue("@Description", s)
MsgBox("NO")
For i As Integer = 0 To GridView1.Rows.Count - 1
DA.SelectCommand = cmd1
DA.Fill(dt)
'row is of a GridViewRow datatype As GridView1.Rows
row.Cells.RemoveAt(i) '' do not know if it is correct or not
'GridView3.DataSource = '' dt tried with no luck
'GridView3.DataBind() '' tried with no luck
cmd1.Dispose()
DA.Dispose()
dt.Clear()
dt.Dispose()
Next
End If
更正確的實施方法是,從GridView的數據源中刪除行,然後調用的DataBind(),而不是它已經被加載之後從GridView的數據。看到線程[這裏](http://stackoverflow.com/questions/592106/how-to-delete-row-from-gridview)。 –
@SandraWalters所以我怎麼才能實現只從GridView中刪除行,因爲我不想從sqlDataSource中刪除原始的'Description',而只是從GridView中刪除 – HShbib