Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I agree with caltrop. I like my markup to be clean and all my aspx/ascx code to reside in my code-behind files (where it belongs).</p> <p>I only have one thing to add. I prefer not to litter my code with OnDataBinding() events wired for each of my databound controls. Instead I do it all in the OnDataBinding() event of the User Control that is being embedded in the bindable-control (such as the repeater in your sample).</p> <p>For example, in my User Control's code-behind you would find:</p> <pre><code>protected override void OnDataBinding(EventArgs e) { base.OnDataBinding(e); litExample.Text = Eval("ExampleField") + " - " + Eval("ExampleField2"); } </code></pre> <p>From here you can set the properties of all your controls or call other methods to set them. Notice how, in my example, I didn't need to perform the boxing like you did here: <code>Literal lit = (Literal)(sender);</code></p> <p>That alone should save you on some performance (nanoseconds of course, but something worth measure). Read the section "Performance" here: <a href="http://msdn.microsoft.com/en-us/library/yz2be5wk%28v=vs.80%29.aspx" rel="nofollow">http://msdn.microsoft.com/en-us/library/yz2be5wk%28v=vs.80%29.aspx</a></p> <p>I am also at war with using strings in my code. I would have either used const string variables to define "ExampleField" and "ExampleField2" or set them up as public properties in the User Control that could then be set by the containing control/page based on the column name of the data object it will be bound against. This affords more flexibility and re-use of the control.</p> <p>FYI: You don not need to call ToString() on Eval, as this method already returns a string.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload