日期:2014-05-18  浏览次数:20493 次

怎么用ASP.NET从web.config中读取出数据路连接字符串,然后绑定到界面上
<TABLE   id= "Table2 "   style= "Z-INDEX:   104;   LEFT:   48px;   WIDTH:   552px;   POSITION:   absolute;   TOP:   232px;   HEIGHT:   26px "
cellSpacing= "1 "   cellPadding= "1 "   rules= "all "   border= "1 "   runat= "server ">
<TR   style= "FONT-WEIGHT:   bold ">
<TD> 数据源名称 </TD>
<TD> 数据库类型 </TD>
<TD> 主机名 </TD>
<TD> 用户名 </TD>
<TD> 登录密码 </TD>
<TD> 数据库名 </TD>
<TD> 删除 </TD>
<TD> 排序 </TD>
</TR>
</TABLE>
按照他绑定

------解决方案--------------------
ConfigurationSettings.AppSettings[ "名称 "]
------解决方案--------------------
顶,不会
------解决方案--------------------
<%#System.Configuration.AppSettings[ "字串 "]%>
------解决方案--------------------
添加System.Configuration
using System.Configuration;
string sconn = ConfigurationManager.ConnectionStrings[ "ConnectionString "].ConnectionString;
web.config里
</configSections> 之下

<connectionStrings>
<add name= "ConnectionString " connectionString= "连接字串 " />
</connectionStrings>
------解决方案--------------------
给你个思路吧。我觉得这样能实现
先在后台 ConfigurationSettings.AppSettings[ "名称 "] 把他里面的字符。复给一个变量
如果需要的。你可以把他们按你要的方式截取。然后把这个变量绑顶到页面上。
我想这样。可以实现~`

------解决方案--------------------
// Show the use of ConnectionStrings.
// If called from within a client application,
// the GetWebApplicationSection(string) gets the default section
// from the machine.config.
// If called from within a Web aplication it gets the
// section from the configuration file located at the
// application current level.
static void GetConnectionStrings()
{

// Get the connectionStrings key,value pairs collection.
ConnectionStringSettingsCollection connectionStrings =
WebConfigurationManager.ConnectionStrings
as ConnectionStringSettingsCollection;

// Get the collection enumerator.
IEnumerator connectionStringsEnum =
connectionStrings.GetEnumerator();

// Loop through the collection and
// display the connectionStrings key, value pairs.
int i = 0;
Console.WriteLine( "[Display connectionStrings] ");
while (connectionStringsEnum.MoveNext())
{
string name = connectionStrings[i].Name;
Console.WriteLine( "Name: {0} Value: {1} ",
name, connectionStrings[name]);
i += 1;
}

Console.WriteLine();
}

------解决方案--------------------
之上是2.0用法,1.1的话按wei123456(onedotone)说的