How to access parameters of SqlDataSource

K

Kees de Winter

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!
 
G

Guest

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.
 
F

Flinky Wisty Pomm

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()
}
 
K

Kees de Winter

That was it! Thanks!!

--
Kees de Winter


clickon said:
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.
 

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. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,534
Members
45,008
Latest member
Rahul737

Latest Threads

Top