tags:

views:

342

answers:

2
   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

This is not working for me. I am trying to iterate a control collection and return one control ID. I am kind of a newbie to linq.

Thanks, ~ck

+1  A: 

I assume that you think there's only one button with a button ID of "ButtonOK"? If so, then replace

btn = qry.ToList()

with

btn = qry.Single()

and things will be how you expect. Right now, you're getting back a List<T> of one item, not a reference to a single item.

mquander
Thank you very much!
Hcabnettek
A: 

Rather than use LINQ, you should just use the FindControl method on ButtonOK's parent.

dahlbyk