Databind the result of a method call : Expressions « Data Binding « ASP.NET Tutorial






<script runat="server" language="C#">
protected void Page_Load(object o, EventArgs e) {
    if(IsPostBack) {
        Page.DataBind();
    }
}

protected double CalculateFactorial(int input) {
    double result = 1;
    for(;input > 0; input--) {
        result *= input;
    }
    return result;
}
</script>
<form runat="server">
Databind the result of a method call.
<asp:Textbox runat="server" id="theInput" /><br/>
<asp:RequiredFieldValidator 
    runat="server"
    ControlToValidate="theInput"
    ErrorMessage="input is required" />
<asp:RangeValidator
    runat="server"
    ControlToValidate="theInput"
    ErrorMessage="input must be >= 0 and < 20"
    Type="integer"
    MinimumValue="0"
    MaximumValue="20" /><br/>
<asp:Button 
    runat="server" 
    type="submit" 
    Text="Calculate Factorial" /><br/>
The result is: <b><%# CalculateFactorial(Int32.Parse(theInput.Text)).ToString() %></b>
</form>








19.15.Expressions
19.15.1.Put simple data binding expressions
19.15.2.Binding Expression
19.15.3.Databind the result of a method call
19.15.4.DataList with data binding expression