根据条件从gridview中删除完整的行 [英] Removing a complete row from a gridview based on a condition
问题描述
如果满足条件,我试图从GridView中删除一个完整的行。
这里我有
Hi, I am trying to remove a complete row from a GridView if it satisfied a condition.
Here I have got
a Description Column from Product table in database
用于填充GridView。我在我的vb应用程序中将sqlcommand设置为仅
with which a GridView is populated. I set the sqlcommand in my vb app to only
select the Description which does not contain the String s
。这里
String s has two keywords "Tomatoes" and "Apple"
。
所以Sql Query应该检索
.
So the Sql Query should retrieve the
Description that does not have "Tomatoes" and "Apple"
因此应该通过删除满足条件的行来更新Gridview。
我在 GridView中删除
and therefore the Gridview should be updated by removing the rows which satisfy the condition.
I am facing a difficulty in removing the
Description row in GridView
有西红柿和苹果。我尝试用结果填充另一个GridView,但它没有出现在网页中,尽管一切都是正确的,因为我已经看到了我指定了一些断点的值。有什么建议或想法?
这是我的代码:
which has "Tomatoes" and "Apple". I tried populating another GridView with the results, but it does not appear in the web page despite the fact that everything is correct because I have seen the values where I specified some Breakpoints. Any suggestions or thoughts?
Here is my code:
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
推荐答案
你可以通过查询对待它,不需要进入代码。
类似于:
You can treat it by Query, no need to get into code.
Something like:
SELECT DISTINCT [Description] FROM [Product] WHERE ([Description] LIKE '%' + @ Description + '%') And ([Description] Not Like '%s%')
这篇关于根据条件从gridview中删除完整的行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!