Solved

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

Posted on 2007-11-29
8
1,741 Views
Last Modified: 2012-06-27
I was hoping to do something like this:

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

0
Comment
Question by:jbrahy
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
8 Comments
 
LVL 22

Expert Comment

by:RedKelvin
ID: 20378220
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
 
LVL 1

Author Comment

by:jbrahy
ID: 20378253
I want to do it from the .aspx, is that possible?
0
 
LVL 7

Expert Comment

by:nisarkhan
ID: 20378347
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
Creating Instructional Tutorials  

For Any Use & On Any Platform

Contextual Guidance at the moment of need helps your employees/users adopt software o& achieve even the most complex tasks instantly. Boost knowledge retention, software adoption & employee engagement with easy solution.

 
LVL 22

Expert Comment

by:RedKelvin
ID: 20378390
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
 
LVL 1

Author Comment

by:jbrahy
ID: 20378444
can I put that codebehind in the a file in the App_Code directory so I don't have to modify every file?
0
 
LVL 22

Expert Comment

by:RedKelvin
ID: 20378508
The best thing would be to put it in a common class
0
 
LVL 10

Accepted Solution

by:
Oliver Amaya earned 500 total points
ID: 20381346
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
 
LVL 1

Author Closing Comment

by:jbrahy
ID: 31411821
thanks, I was getting an unrelated error and after going back through it it's working. thanks!
0

Featured Post

Webinar: Aligning, Automating, Winning

Join Dan Russo, Senior Manager of Operations Intelligence, for an in-depth discussion on how Dealertrack, leading provider of integrated digital solutions for the automotive industry, transformed their DevOps processes to increase collaboration and move with greater velocity.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

739 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question