locked
How do I pass a value from a ViewState into a ObjectDataSource parameter? RRS feed

  • Question

  • User-356562709 posted

    Hi there

    Here is my code:

        public string DateBegin
        {
            get
            {
                if (null != ViewState["DateBegin"])
                    return (string)ViewState["DateBegin"];
                else
                    return DateTime.Now.ToUniversalTime().ToString("MM/dd/yyyy") + " 00:00:00 AM";
            }
            set
            {
                ViewState["DateBegin"] = value;
            }
        }

    and:

    		if (!Page.IsPostBack)
    		{
                DateBegin = DateTime.Now.ToUniversalTime().ToString("MM/dd/yyyy") + " 00:00:00 AM";
    ...
    

    Markup:

        <asp:ObjectDataSource ID="sourceJobHistory" runat="server"
            ...">
            <SelectParameters>
                <asp:Parameter Name="startRowIndex"  Type="Int32" />
                <asp:Parameter Name="pageSize"       Type="Int32"/>
                <asp:Parameter Name="sortExpression" Type="String" />    
                
                <!-- problem is to pass the value into here -->
                <asp:Parameter Name="DateBegin"  Type="String" />    
       
            </SelectParameters>
        </asp:ObjectDataSource>

    Any ideas? Thank you!

    Friday, May 20, 2011 4:33 PM

Answers

  • User-1360095595 posted

    Handle the ODS' Selecting event.  In there you can set e.InputParameters[index/key] to whatever value you want.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, May 20, 2011 4:41 PM