Solved

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

Posted on 2007-11-29
8
1,751 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
Containers & Docker to Create a Powerful Team

Containers are an incredibly powerful technology that can provide you and/or your engineering team with huge productivity gains. Using containers, you can deploy, back up, replicate, and move apps and their dependencies quickly and easily.

 
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

Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

Question has a verified solution.

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

Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
There's a multitude of different network monitoring solutions out there, and you're probably wondering what makes NetCrunch so special. It's completely agentless, but does let you create an agent, if you desire. It offers powerful scalability …
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

623 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