数据源绑定使用配置文件连接字符串 [英] Bind DataSource Using Config File Connection String

查看:138
本文介绍了数据源绑定使用配置文件连接字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的web.config文件中定义的连接字符串。我用了code本身这个连接字符串。然而,对于数据源(绑定到下拉列表)我选择它使用的数据源配置过程。这将导致分离,这意味着,如果连接字符串的变化,我必须改变它在多个地方。

I have a Connection String defined in my web.config file. I use this connection string in the code itself. However, for DataSources (bound to dropdown lists) I select it using the Data Source Configuration process. This causes a separation that means, if the connection string changes, I have to change it in more than one place.

有没有一种方法来指web.config中的连接字符串与下拉列表中的数据源?

Is there a way to refer to the web.config connection string with the DataSources on the dropdown lists?

推荐答案

您需要这个。 ;)

<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:SiteSqlServer %>" SelectCommand="SPNAME" SelectCommandType="StoredProcedure">
                <SelectParameters>
                    <asp:Parameter Name="Id" Type="Int32" />
                </SelectParameters>
            </asp:SqlDataSource>

有关获得所有连接字符串中DROPDOWNLIST:

for get all connection strings in Dropdownlist:

  foreach (var s in System.Web.Configuration.WebConfigurationManager.ConnectionStrings)  {
    Response.Write(s);  }

这篇关于数据源绑定使用配置文件连接字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆