Solved

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

Posted on 2007-11-29
8
1,731 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
Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

 
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

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
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…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

828 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