2009-06-29 79 views
1
Private Function GetWebDataGridOKButtonId() As String 
     Dim ctls As ControlCollection = _ 
     WebDataGrid1.Controls(0).Controls(0).Controls 

     Dim btn As Button 
     Dim qry = From item As Control In ctls _ 
      Where item.ID = "ButtonOK" _ 
     Select item 

     btn = qry.ToList() 

     Return btn.ClientID 

    End Function 

這不適用於我。我正在嘗試迭代控件集合並返回一個控件ID。我對linq很有新意。Linq迭代控件集合

感謝, 〜CK

+0

它會拋出任何錯誤嗎?如果是這樣,你可以發佈嗎? – shahkalpesh 2009-06-29 19:08:20

回答

1

我假設你認爲只有一個按鈕,「ButtonOK」的按鈕ID?如果是這樣,然後用

btn = qry.Single() 

和事物取代

btn = qry.ToList() 

將是你如何期望。現在,您將獲得一個項目的List<T>,而不是對單個項目的引用。

+0

非常感謝! – Hcabnettek 2009-07-15 14:53:35

4

您不應該使用LINQ,而應該在Button的父項上使用FindControl方法。