Solved

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

Posted on 2007-11-29
8
1,719 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
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
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 
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:
joex911 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

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
In a recent question (https://www.experts-exchange.com/questions/28997919/Pagination-in-Adobe-Acrobat.html) here at Experts Exchange, a member asked how to add page numbers to a PDF file using Adobe Acrobat XI Pro. This short video Micro Tutorial sh…
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…

785 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