<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://www.aspnetzone.de/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>Peter Bucher : Tipps, NamingContainer</title><link>http://www.aspnetzone.de/blogs/peterbucher/archive/tags/Tipps/NamingContainer/default.aspx</link><description>Ordnungsbegriffe: Tipps, NamingContainer</description><dc:language /><generator>CommunityServer 2.1 SP2 (Build: 61120.2)</generator><item><title>Nach Event an die GridViewRow kommen, von dem das auslösende Control stammt</title><link>http://www.aspnetzone.de/blogs/peterbucher/archive/2008/09/17/nach-event-an-die-gridviewrow-kommen-von-dem-das-ausl-sende-control-stammt.aspx</link><pubDate>Wed, 17 Sep 2008 09:55:00 GMT</pubDate><guid isPermaLink="false">ce930855-ae9b-4fa4-8077-06a76071cc6a:202075</guid><dc:creator>Peter Bucher</dc:creator><slash:comments>0</slash:comments><comments>http://www.aspnetzone.de/blogs/peterbucher/comments/202075.aspx</comments><wfw:commentRss>http://www.aspnetzone.de/blogs/peterbucher/commentrss.aspx?PostID=202075</wfw:commentRss><description>&lt;P&gt;Diese Frage kommt ab und zu in den Foren, die Lösung ist denkbar einfach.&lt;/P&gt;
&lt;P&gt;Bei einem Button der in einer GridViewRow steckt, kann im Handler bspw. so auf die korrespondierende GridViewRow zugegriffen werden:&lt;/P&gt;&lt;PRE&gt;&lt;DIV class=CodeBox&gt;
&lt;code&gt;&lt;span style="color: Black;background-color: Transparent;font-family: Courier New;font-size: 14px;font-weight: normal;"&gt;&lt;span style="color: Blue;background-color: Transparent;font-family: Courier New;font-size: 14px;font-weight: normal;"&gt;protected&lt;/span&gt; &lt;span style="color: Blue;background-color: Transparent;font-family: Courier New;font-size: 14px;font-weight: normal;"&gt;void&lt;/span&gt; Button_Click(&lt;span style="color: Blue;background-color: Transparent;font-family: Courier New;font-size: 14px;font-weight: normal;"&gt;object&lt;/span&gt; sender, EventArgs e) {&lt;br /&gt;    GridViewRow &lt;span style="color: Red;background-color: Transparent;font-family: Courier New;font-size: 14px;font-weight: normal;"&gt;=&lt;/span&gt; (GridViewRow)(sender &lt;span style="color: Blue;background-color: Transparent;font-family: Courier New;font-size: 14px;font-weight: normal;"&gt;as&lt;/span&gt; Control).NamingContainer;&lt;br /&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/DIV&gt;&lt;/PRE&gt;
&lt;DIV&gt;&lt;/DIV&gt;
&lt;P&gt;Das selbe bei anderen Controls, die einen Event auslösen können:&lt;/P&gt;
&lt;DIV class=CodeBox&gt;&lt;code&gt;&lt;span style="color: Black;background-color: Transparent;font-family: Courier New;font-size: 14px;font-weight: normal;"&gt;&lt;span style="color: Blue;background-color: Transparent;font-family: Courier New;font-size: 14px;font-weight: normal;"&gt;protected&lt;/span&gt; &lt;span style="color: Blue;background-color: Transparent;font-family: Courier New;font-size: 14px;font-weight: normal;"&gt;void&lt;/span&gt; List_SelectedIndexChanged(&lt;span style="color: Blue;background-color: Transparent;font-family: Courier New;font-size: 14px;font-weight: normal;"&gt;object&lt;/span&gt; sender, EventArgs e) {&lt;br /&gt;    GridViewRow &lt;span style="color: Red;background-color: Transparent;font-family: Courier New;font-size: 14px;font-weight: normal;"&gt;=&lt;/span&gt; (GridViewRow)(sender &lt;span style="color: Blue;background-color: Transparent;font-family: Courier New;font-size: 14px;font-weight: normal;"&gt;as&lt;/span&gt; Control).NamingContainer;&lt;br /&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/DIV&gt;&lt;BR&gt;Erklärung:&lt;BR&gt;NamingContainer steht für .Parent.Parent.&lt;BR&gt;Da das eventauslösende Control in einer Hierarchie steht, kann mithilfe dieser Eigenschaften,die Hierarchie hinaufgeklettert werden. &lt;img src="http://www.aspnetzone.de/aggbug.aspx?PostID=202075" width="1" height="1"&gt;</description><category domain="http://www.aspnetzone.de/blogs/peterbucher/archive/tags/ASP.NET/default.aspx">ASP.NET</category><category domain="http://www.aspnetzone.de/blogs/peterbucher/archive/tags/Tipps/default.aspx">Tipps</category><category domain="http://www.aspnetzone.de/blogs/peterbucher/archive/tags/GridView/default.aspx">GridView</category><category domain="http://www.aspnetzone.de/blogs/peterbucher/archive/tags/GridViewRow/default.aspx">GridViewRow</category><category domain="http://www.aspnetzone.de/blogs/peterbucher/archive/tags/NamingContainer/default.aspx">NamingContainer</category><category domain="http://www.aspnetzone.de/blogs/peterbucher/archive/tags/Parent/default.aspx">Parent</category></item></channel></rss>