Search code examples
asp.netlinqlinqdatasource

LinqDataSource: How to define a default value


Is it legal to define a default value for a parameter the way I am in the code below? It keeps throwing an "Input string was not in a correct format." error for me.
Is there a different way I should be doing this?

        <asp:LinqDataSource ID="lds_numbers" runat="server" ContextTypeName="nrm.prop.myDataContext"
            TableName="Sources" Where="myNumber== @myNumber" EnableDelete="True"
            EnableInsert="True" EnableUpdate="True">
            <WhereParameters>
                <asp:Parameter DefaultValue='<%= this.StateItems["myNumber"] %>' Name="myNumber" Type="Int32" />
            </WhereParameters>
.
.
.

Solution

  • Found a way around it by setting the default values in the PageLoad event in the code behind.

        protected void Page_Load(object sender, EventArgs e)
        {
            lds_numbers.InsertParameters[0].DefaultValue = this.StateItems["myNumber"].ToString();
            lds_numbers.WhereParameters[0].DefaultValue = this.StateItems["myNumber"].ToString();
        }