views:

47

answers:

2

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>
.
.
.
A: 

I would create a stored procedure with parameter MyNumber, Drag&drop it to diagram. Than you need to setup return type to "Sources". Than it is easy and native to execute it like DataContext.SelectSources(5);

Sergey Osypchuk
A: 

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();
    }
Abe Miessler