ObjectDataSource Parameter Passing

Discussion in 'ASP .Net' started by Guest, Apr 14, 2006.

  1. Guest

    Guest Guest

    What is the best way to pass a parameter to an ObjectDataSource.
    I am able to add a new parameter to the SelectParameters, but I would like
    to just assign a value to an existing parmeter at runtime.

    Currently I am just adding the parameter at runtime and setting the value:
    ObjectDataSource1.SelectParameters.Add("searchCCN", "")

    I would like to accomplish the following:
    ObjectDataSource1.SelectParameters.("LastName") = "Doe"

    The code above does not work. There is no parameter.value, only
    parameter.DefaultValue. Is there a better way to set an existing parameter
    value in an ObjectDataSource?

    Thanks,
     
    Guest, Apr 14, 2006
    #1
    1. Advertisements

  2. Guest

    Guest Guest

    The DefaultValue is the correct way to set such parameters at run-time.
    (There is no databound value to replace it)
     
    Guest, Apr 14, 2006
    #2
    1. Advertisements

  3. Guest

    Guest Guest

    Thanks for the reply. I have a follow-up question:

    Should I use the Default Value or add the parameter for best practice?

    1) ObjectDataSource1.SelectParameters("LastNam").DefaultValue="Doe"

    2) ObjectDataSource1.SelectParameters.Add("LastName", "Doe")
     
    Guest, Apr 14, 2006
    #3
  4. Guest

    Guest Guest

    I prefer to specify the parameter type to ensure type-casting is done
    correctly particularly when the value might be affected by the Culture
    setting of the server running the application. e.g.

    ObjectDataSource1.SelectParameters.Add(New
    WebControls.Parameter("OrderDate", TypeCode.DateTime, Now.ToString()))
     
    Guest, Apr 14, 2006
    #4
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.