Set <SelectParameters> To Constant Values

M

MikeB

Hello All, how can I set my selectparameter to a constant value within my
constants class or to a value in my web.config file?
 
G

Guest

Howdy,

I guess meant data source controls (sqldatasource, objectdatasource etc)

1. First way in Web config:

<configuration>
<appSettings>
<add key="Parameter1DefaultValue" value="5"/>
</appSettings>
<system.web>
... everything else...
</system.web>
<configuration>

aspx page:
<asp:ObjectDataSource runat="server" ID="ds" SelectMethod="MethodName"
TypeName="ClassName" >
<SelectParameters>
<asp:parameter Name="parameter1" Type="Int32" DefaultValue="<%$
AppSettings:parameter1DefaultValue %>" />
</SelectParameters>
</asp:ObjectDataSource>


2. second apprach, contants class (set value programatically)

<asp:ObjectDataSource runat="server" ID="ds" SelectMethod="MethodName"
TypeName="ClassName" OnSelecting="ds_Selecting" >
<SelectParameters>
<asp:parameter Name="parameter1" Type="Int32"/>
</SelectParameters>
</asp:ObjectDataSource>

protected void ds_Selecting(object sender,
ObjectDataSourceSelectingEventArgs e)
{
e.InputParameters["parameter1"] = 5; // use your contants here
}


Hope this helps
 
M

MikeB

Yes, you are correct, that is what I meant, sorry for not being clear.
Also, that is exactly what I was looking for. Thank you very much.


Milosz Skalecki said:
Howdy,

I guess meant data source controls (sqldatasource, objectdatasource etc)

1. First way in Web config:

<configuration>
<appSettings>
<add key="Parameter1DefaultValue" value="5"/>
</appSettings>
<system.web>
... everything else...
</system.web>
<configuration>

aspx page:
<asp:ObjectDataSource runat="server" ID="ds" SelectMethod="MethodName"
TypeName="ClassName" >
<SelectParameters>
<asp:parameter Name="parameter1" Type="Int32" DefaultValue="<%$
AppSettings:parameter1DefaultValue %>" />
</SelectParameters>
</asp:ObjectDataSource>


2. second apprach, contants class (set value programatically)

<asp:ObjectDataSource runat="server" ID="ds" SelectMethod="MethodName"
TypeName="ClassName" OnSelecting="ds_Selecting" >
<SelectParameters>
<asp:parameter Name="parameter1" Type="Int32"/>
</SelectParameters>
</asp:ObjectDataSource>

protected void ds_Selecting(object sender,
ObjectDataSourceSelectingEventArgs e)
{
e.InputParameters["parameter1"] = 5; // use your contants here
}


Hope this helps
--
Milosz


MikeB said:
Hello All, how can I set my selectparameter to a constant value within my
constants class or to a value in my web.config file?
 

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

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,057
Latest member
KetoBeezACVGummies

Latest Threads

Top