My favorites
▼
|
Sign in
ra-ajax
Ra Ajax - Managed Ajax for ASP.NET
Project Home
Downloads
Wiki
Issues
Source
Checkout
Browse
Changes
Source path:
svn
/
trunk
/
Ra.Selector
/
Selector.cs
‹r1532
r1622
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
/*
* Ra-Ajax - A Managed Ajax Library for ASP.NET and Mono
* Copyright 2008 - 2009 - Thomas Hansen thomas@ra-ajax.org
* This code is licensed under the GPL version 3 which
* can be found in the license.txt file on disc.
*
*/
using System;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Collections.Generic;
namespace Ra.Selector
{
/**
* Helper class for doing selector queries on Controls to retrieve specific
* Controls in Page hierarchy. Kind of like a CSS selector only for the server-side.
* This class can be very handsome in scenarios where you have GridViews or Data Repeators
* which are dynamically databound and you for some reason cannot use the ID directly or something
* but still need to traverse server-side Control hierarchy to find a specific control...
*/
public static class Selector
{
/**
* Recursively searches Control hierarchy for matches for Predicate and returns it as T
*/
public static T SelectFirst<T>(Control from, Predicate<Control> predicate) where T : Control
{
if (predicate(from))
return from as T;
foreach (Control idx in from.Controls)
{
T tmpRetVal = SelectFirst<T>(idx, predicate);
if (tmpRetVal != null)
return tmpRetVal;
}
return null;
}
/**
* Recursively searches Control hierarchy for the first control that
* matches the type of T and returns it as T
*/
public static T SelectFirst<T>(Control from) where T : Control
{
return SelectFirst<T>(from,
delegate(Control idx)
{
return idx is T;
});
}
/**
* Recursively searches Control hierarchy for the first control that
* have the given ID and returns it as T. Kind of like the "recursive FindControl"
*/
public static T FindControl<T>(Control from, string id) where T : Control
{
return SelectFirst<T>(from,
delegate(Control idx)
{
return idx.ID == id;
});
}
/**
* Recursively search Control hierarcy for ALL controls that
* matches the given Predicate and returns them as T
*/
public static IEnumerable<T> Select<T>(Control from, Predicate<Control> predicate) where T : Control
{
if (from is T)
{
if (predicate(from))
yield return from as T;
}
foreach (Control idx in from.Controls)
{
foreach (T idxInner in Select<T>(idx, predicate))
{
yield return idxInner;
}
}
}
/**
* Recursively search Control hierarcy for ALL controls that
* matches the type of T and returns them as T
*/
public static IEnumerable<T> Select<T>(Control from) where T : Control
{
return Select<T>(from,
delegate(Control idx)
{
return idx is T;
});
}
}
}
Show details
Hide details
Change log
r1540
by polterguy on Jul 14, 2009
Diff
Carriage return fixing...
Go to:
...Builder/DeterministicExecutor.cs
/trunk/Ra.Builder/Element.cs
/trunk/Ra.Builder/HtmlBuilder.cs
...Extensions/Helpers/CometQueue.cs
....Extensions/Widgets/Accordion.cs
...ensions/Widgets/AccordionView.cs
...ensions/Widgets/AutoCompleter.cs
...ons/Widgets/AutoCompleterItem.cs
...a.Extensions/Widgets/Calendar.cs
...k/Ra.Extensions/Widgets/Comet.cs
...nsions/Widgets/DateTimePicker.cs
....Extensions/Widgets/ExtButton.cs
...xtensions/Widgets/InPlaceEdit.cs
...nk/Ra.Extensions/Widgets/Menu.cs
...a.Extensions/Widgets/MenuItem.cs
...Extensions/Widgets/MessageBox.cs
...ensions/Widgets/ResizeHandler.cs
...a.Extensions/Widgets/RichEdit.cs
...k/Ra.Extensions/Widgets/Timer.cs
...Ra.Extensions/Widgets/WebPart.cs
.../Ra.Extensions/Widgets/Window.cs
...s/Ajax-Forum-Starter-Kit.aspx.cs
.../Ra.Samples/App_Code/Activity.cs
.../Ra.Samples/App_Code/Customer.cs
...k/Ra.Samples/App_Code/Message.cs
/trunk/Ra.Samples/App_Code/Node.cs
...nk/Ra.Samples/App_Code/People.cs
/trunk/Ra.Samples/App_Code/RSS.cs
...nk/Ra.Samples/CRM-Sample.aspx.cs
.../Ra.Samples/Chart-Sample.aspx.cs
/trunk/Ra.Samples/Default.aspx.cs
.../Ra.Samples/MasterPage.master.cs
...nk/Ra.Samples/RSS-Sample.aspx.cs
...ort-Calendar-Starter-Kit.aspx.cs
...Viewport-RSS-Starter-Kit.aspx.cs
....Samples/Viewport-Sample.aspx.cs
/trunk/Ra.Selector/Selector.cs
/trunk/Ra.WebSite/App_Code/Blog.cs
.../Ra.WebSite/App_Code/DocsItem.cs
.../Ra.WebSite/App_Code/Operator.cs
/trunk/Ra.WebSite/Author.aspx.cs
/trunk/Ra.WebSite/Blog.aspx.cs
/trunk/Ra.WebSite/BlogItem.aspx.cs
/trunk/Ra.WebSite/Blogs.aspx.cs
/trunk/Ra.WebSite/Default.aspx.cs
...aviors.BehaviorDraggable.ascx.cs
...aviors.BehaviorDroppable.ascx.cs
...viors.BehaviorObscurable.ascx.cs
...haviors.BehaviorUnveiler.ascx.cs
...ehaviors.BehaviorUpdater.ascx.cs
Project members,
sign in
to write a code review
Older revisions
r1532
by kariem.elkoush on Jun 24, 2009
Diff
[No log message]
r1527
by kariem.elkoush on Jun 22, 2009
Diff
[No log message]
r1525
by kariem.elkoush on Jun 19, 2009
Diff
[No log message]
All revisions of this file
File info
Size: 3434 bytes, 100 lines
View raw file
Powered by
Google Project Hosting