2014-09-12 89 views
0

訪問單獨的行模板,我在TemplateFieldListBox(名爲ListBoxProperty)和button(btnDeselectAll)上gridview控制,顯示在gridview的每一行。下面顯示的代碼是TemplateField中按鈕控件背後的代碼。此代碼適用於gridview中每行的每個ListBox。我希望它僅影響點擊它的gridview行中的ListBox。我嘗試了一些失敗的東西,所以我沒有包括我的失敗 - 只是幾乎給我我想要的部分。不能包含照片,唉,我的聲譽很薄弱。在GridView控件

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

按鈕的NamingContainerGridViewRow,有你。

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 
+0

相當完美。非常感謝。 – 2014-09-12 19:55:45