Link to home
Start Free TrialLog in
Avatar of jbrahy
jbrahy

asked on

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>

Avatar of RedKelvin
RedKelvin

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

Avatar of jbrahy

ASKER

I want to do it from the .aspx, is that possible?
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
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()%>'
Avatar of jbrahy

ASKER

can I put that codebehind in the a file in the App_Code directory so I don't have to modify every file?
The best thing would be to put it in a common class
ASKER CERTIFIED SOLUTION
Avatar of Oliver Amaya
Oliver Amaya
Flag of Venezuela, Bolivarian Republic of image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of jbrahy

ASKER

thanks, I was getting an unrelated error and after going back through it it's working. thanks!