how do I pass a parameter from web.config AppSettings to a SqlDataSource?

I was hoping to do something like this:

    <SelectParameters>
      <asp:Parameter DefaultValue="<%$ AppSettings:StatusID %>"  Type="int32" Name="StatusID" />
   </SelectParameters>

LVL 1
jbrahyAsked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
Oliver AmayaConnect With a Mentor EntrepeneurCommented:
Hi jbrahy, the way you suggested it should work, what error are you getting?
<asp:Parameter DefaultValue="<%$ AppSettings:StatusID %>"  Type="int32" Name="StatusID" />

Open in new window

0
 
RedKelvinCommented:
Define your app settings normally, then you can access them from your codebehind like this


string strVal = system.Configuration.ConfigurationManager.AppSettings("STATUS_ID")

Open in new window

0
 
jbrahyAuthor Commented:
I want to do it from the .aspx, is that possible?
0
Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

 
nisarkhanCommented:
see if you can:

 <asp:Parameter DefaultValue="<%# system.Configuration.ConfigurationManager.AppSettings("STATUS_ID") %>"  Type="int32" Name="StatusID" />

if not, then i would say stick with code-behind.

hth
0
 
RedKelvinCommented:
Yes, you can, but you will still need to code some codebehind.

First declare a property like this, in your codebehind, this will get the appsettings val

          public string StatusId
          {
              get
              {
                  return system.Configuration.ConfigurationManager.AppSettings("STATUS_ID");
              }
          }

Now you can access the StatusId property in your aspx (markup page)

<%# StatusId()%>

for example if you want to set the text of a label

text='<%# TypeCode()%>'
0
 
jbrahyAuthor Commented:
can I put that codebehind in the a file in the App_Code directory so I don't have to modify every file?
0
 
RedKelvinCommented:
The best thing would be to put it in a common class
0
 
jbrahyAuthor Commented:
thanks, I was getting an unrelated error and after going back through it it's working. thanks!
0
All Courses

From novice to tech pro — start learning today.