我在ListBox
控件上的button
中有一个TemplateField
(名为ListBoxProperty)和gridview
(btnDeselectAll),显示在{{1}的每一行上}。下面显示的代码是gridview
中按钮控件背后的代码。此代码适用于TemplateField
中每一行ListBox
的每个gridview
。我希望它只影响从中单击它的gridview行中的ListBox
。我已经尝试了一些失败的事情,所以我没有包括我的失败 - 只是几乎给了我想要的东西。不能包含图片,我的名声很弱。
Protected Sub btnDeselectAll_Click(sender As Object, e As System.EventArgs)
For Each Row As GridViewRow In GridView1.Rows
Dim myListBox As ListBox = _
CType(Row.FindControl("ListBoxProperty"), ListBox)
For Each selectedItem As ListItem In myListBox.Items
selectedItem.Selected = False
Next
Next
End Sub
答案 0 :(得分:0)
按钮的NamingContainer
是GridViewRow
,你就是。
Protected Sub btnDeselectAll_Click(sender As Object, e As System.EventArgs)
Dim btn = DirectCast(sender, Button)
Dim row = DirectCast(btn.NamingContainer, GridViewRow)
Dim myListBox = DirectCast(row.FindControl("ListBoxProperty"), ListBox)
For Each selectedItem As ListItem In myListBox.Items
selectedItem.Selected = False
Next
End Sub