How to access parameters of SqlDataSource

Discussion in 'ASP .Net' started by Kees de Winter, Mar 29, 2006.

  1. Hi,

    I am trying to set a parameter in the SELECT statement of a SqlDataSource,
    in the Page_Load event where the intended value for the parameter is
    calculated. But how can I set the parameter to a certain value? If the value
    comes from a control, form, querystring etc. then it's easily done
    declaratively. But how to do it in code.

    Have tried for hours. I will be grateful for all help!
    --
    Kees de Winter
    Kees de Winter, Mar 29, 2006
    #1
    1. Advertising

  2. You could do it all programatically, set the SQLDataSource.SelectCommand
    property and use the SQLDataSource.SelectParameter.Add() method to add the
    parameter. Alternativley you could use the SQLDataSource.FilterExpression
    and the SQLDataSource.FilterParameters properties to filter the data after
    the fact.

    "Kees de Winter" wrote:

    > Hi,
    >
    > I am trying to set a parameter in the SELECT statement of a SqlDataSource,
    > in the Page_Load event where the intended value for the parameter is
    > calculated. But how can I set the parameter to a certain value? If the value
    > comes from a control, form, querystring etc. then it's easily done
    > declaratively. But how to do it in code.
    >
    > Have tried for hours. I will be grateful for all help!
    > --
    > Kees de Winter
    >
    >
    >
    =?Utf-8?B?Y2xpY2tvbg==?=, Mar 29, 2006
    #2
    1. Advertising

  3. If you want to provide a default value for your parameter, and the
    param is defined in the aspx file, just do.

    protected void Page_Load(object sender, EventArgs e)
    {
    // do page load stuff
    SetQueryDefaults();
    }

    private void SetQueryDefaults()
    {
    MySqlDataSource.SelectParameters["ParameterName"].DefaultValue =
    MyValue.ToString()
    }
    Flinky Wisty Pomm, Mar 29, 2006
    #3
  4. That was it! Thanks!!

    --
    Kees de Winter


    "clickon" <> wrote in message
    news:...
    > You could do it all programatically, set the SQLDataSource.SelectCommand
    > property and use the SQLDataSource.SelectParameter.Add() method to add the
    > parameter. Alternativley you could use the

    SQLDataSource.FilterExpression
    > and the SQLDataSource.FilterParameters properties to filter the data after
    > the fact.
    >
    > "Kees de Winter" wrote:
    >
    > > Hi,
    > >
    > > I am trying to set a parameter in the SELECT statement of a

    SqlDataSource,
    > > in the Page_Load event where the intended value for the parameter is
    > > calculated. But how can I set the parameter to a certain value? If the

    value
    > > comes from a control, form, querystring etc. then it's easily done
    > > declaratively. But how to do it in code.
    > >
    > > Have tried for hours. I will be grateful for all help!
    > > --
    > > Kees de Winter
    > >
    > >
    > >
    Kees de Winter, Mar 29, 2006
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?Utf-8?B?TWFydGluIEJpc2Nob2Zm?=

    Modify SqlDataSource parameters before select

    =?Utf-8?B?TWFydGluIEJpc2Nob2Zm?=, Oct 20, 2005, in forum: ASP .Net
    Replies:
    5
    Views:
    27,972
    Steven Cheng[MSFT]
    Oct 25, 2005
  2. Replies:
    1
    Views:
    440
    =?Utf-8?B?Sml0ZXNo?=
    Dec 22, 2005
  3. =?Utf-8?B?RGFiYmxlcg==?=

    modify SqlDataSource parameters in code behind?

    =?Utf-8?B?RGFiYmxlcg==?=, Apr 4, 2006, in forum: ASP .Net
    Replies:
    2
    Views:
    28,328
    =?Utf-8?B?RGFiYmxlcg==?=
    Apr 4, 2006
  4. =?Utf-8?B?R3JlaWY=?=

    Setting Parameters for SqlDataSource control

    =?Utf-8?B?R3JlaWY=?=, Jun 23, 2006, in forum: ASP .Net
    Replies:
    0
    Views:
    415
    =?Utf-8?B?R3JlaWY=?=
    Jun 23, 2006
  5. =?Utf-8?B?RGFuaWVsIFIuIEgu?=

    Problems with Parameters and SQLDataSource

    =?Utf-8?B?RGFuaWVsIFIuIEgu?=, Jul 19, 2006, in forum: ASP .Net
    Replies:
    6
    Views:
    9,605
    roadhawk
    Dec 31, 2009
Loading...

Share This Page