tag:blogger.com,1999:blog-171924705653813582.post6673125968458923327..comments2022-04-01T18:38:53.286+03:00Comments on It Could Be Done!: Implementing ITemplate as Anonymous MethodYuriy Solodkyyhttp://www.blogger.com/profile/04926659302956943479noreply@blogger.comBlogger4125tag:blogger.com,1999:blog-171924705653813582.post-1917522137410904002008-10-17T15:53:00.000+03:002008-10-17T15:53:00.000+03:00Check out the following link, I used it to do an E...Check out the following link, I used it to do an Eval from code-behind... basically you add a handler for databinding and use the DataBinder.Eval() function to pull it off.<BR/><BR/><BR/>http://forums.asp.net/t/1298261.aspx<BR/><BR/>Good luck!Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-171924705653813582.post-46155078026662916052008-10-03T12:34:00.000+03:002008-10-03T12:34:00.000+03:00Thanks for the tip!I also needed to add a "Eval-li...Thanks for the tip!<BR/><BR/>I also needed to add a "Eval-like" statement to this, to be able to dynamically bind the content of the TemplateField with the data object.<BR/><BR/>A solution is to use the DataBinding event of the template's controls, like this:<BR/><BR/> TemplateField emailField = new TemplateField();<BR/> emailField.HeaderText = "Dynamically Added E-Mail Field";<BR/> emailField.ItemTemplate = new GenericTemplateImplementation( delegate( Control container )<BR/> {<BR/> Button btn = new Button();<BR/> btn.DataBinding += new EventHandler(btn_DataBinding);<BR/> container.Controls.Add(btn);<BR/> } );<BR/> GridView1.Columns.Add( emailField );<BR/> <BR/>-----<BR/><BR/> void btn_DataBinding( object sender, EventArgs e )<BR/> {<BR/> Button btn = (Button)sender;<BR/> object dataItem = DataBinder.GetDataItem(btn.NamingContainer);<BR/> btn.Text = (string)DataBinder.Eval(dataItem, "TheBoundedProperty");<BR/><BR/> // or rather, if you know the dataItem's type (called 'MyDataType' here):<BR/> MyDataType dataItem = (MyDataType)DataBinder.GetDataItem(btn.NamingContainer);<BR/> btn.Text = dataItem.TheBoundedProperty;<BR/> }Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-171924705653813582.post-24146435501114139882008-04-16T23:43:00.000+03:002008-04-16T23:43:00.000+03:00How would you add a Eval statement to this? Take:[...How would you add a Eval statement to this? Take:<BR/><BR/>[ asp:LinkButton ID="lnk" runat="server" CommandName="lnk" <BR/> CommandArgument='< % #Eval("Id") % > '] < % #Eval("Name") % > [ / asp:LinkButton]colinbashbashhttps://www.blogger.com/profile/03969335674433118497noreply@blogger.comtag:blogger.com,1999:blog-171924705653813582.post-33581941978582636732008-03-30T06:22:00.000+03:002008-03-30T06:22:00.000+03:00Thanks...this really helped out with creating dyna...Thanks...this really helped out with creating dynamic controls.Anonymousnoreply@blogger.com