关于自定义控件的属性问题,请进 你说的 “Font又回到了以前状态”是什么意思啊?不懂,请详细说明 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 web:接下来是有关用户控件属性的问题:<%@ Import Namespace="System.Data" %><%@ Import Namespace="System.Data.SqlClient" %><script language="C#" runat="server"> string ConnStr; public string ConnectionString { get {return ConnStr;} set {ConnStr = value;} } //这里定义了属性ConnectionString ,具体用法见后面 public void Page_Load(Object Source, EventArgs E) { if (!IsPostBack) { SqlConnection myConnection; SqlCommand myCommand; SqlDataReader myReader; string SQL; SQL = "select * from Shippers"; if (ConnStr == "")//设置默认连接字符串 ConnStr = ConfigurationSettings.AppSettings["DsnNorthwind"]; myConnection = new SqlConnection(ConnStr); myConnection.Open(); myCommand = new SqlCommand(SQL, myConnection); myReader = myCommand.ExecuteReader(); while (myReader.Read()) ShipMethod.Items.Add(new ListItem(myReader["CompanyName"].ToString(), myReader["ShipperID"].ToString())); } }</script><asp:DropDownList id="ShipMethod" runat="server"/> 在aspx文件中用法:<%@ Page Language="C#" %><%@ Register tagprefix="wrox" Tagname="shipment" Src="shipmethod_prop.ascx" %><html><head> <title>Testing our User Control - Part 2</title></head><script runat="server"> void Page_Load(Object sender, EventArgs e) { ShipMethod.ConnectionString = ConfigurationSettings.AppSettings["DsnNorthwind"]; }//注意这儿 </script><body><form runat="server"><strong>Here is some body text.</strong><P>Please choose a shipping method: <wrox:shipment id="ShipMethod" runat="server" /></P></form></body></html>还有种方法:<wrox:shipment ConnectionString="server=localhost;uid=sa;pwd=;database=Northwind" runat="server" />即:把ConnectionString和值放入wrox:shipment用户控件中作为属性 意思是我在设计状态下可以把字体设成小二,但一运行程序,字体又变成了9号,也就是说font属性不能保存 你font属性是定义在用户控件中的?? C# 填充数据 切换桌面背景的问题 增加缩进量 减少缩进量 如何实现 无法从带有索引像索格式的图像创建 Graphics 对像。 可以使用动态类型名来创建对象么? --------------C#.net项目实战,高手们请进来看看.---------------- xml读取分析 C# .Net ACCESS 关于ADOX创建Access数据库的问题 急!求打包Excel方法! 如何用程序實現按“Tab”鍵後自動轉換成按回車鍵? 分析Access数据类型
接下来是有关用户控件属性的问题:
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.SqlClient" %><script language="C#" runat="server">
string ConnStr; public string ConnectionString
{
get {return ConnStr;}
set {ConnStr = value;}
}
//这里定义了属性ConnectionString ,具体用法见后面 public void Page_Load(Object Source, EventArgs E)
{
if (!IsPostBack)
{
SqlConnection myConnection;
SqlCommand myCommand;
SqlDataReader myReader;
string SQL; SQL = "select * from Shippers";
if (ConnStr == "")//设置默认连接字符串
ConnStr = ConfigurationSettings.AppSettings["DsnNorthwind"]; myConnection = new SqlConnection(ConnStr);
myConnection.Open(); myCommand = new SqlCommand(SQL, myConnection); myReader = myCommand.ExecuteReader(); while (myReader.Read())
ShipMethod.Items.Add(new ListItem(myReader["CompanyName"].ToString(), myReader["ShipperID"].ToString()));
}
}
</script><asp:DropDownList id="ShipMethod" runat="server"/> 在aspx文件中用法:
<%@ Page Language="C#" %><%@ Register tagprefix="wrox" Tagname="shipment" Src="shipmethod_prop.ascx" %><html>
<head>
<title>Testing our User Control - Part 2</title>
</head><script runat="server"> void Page_Load(Object sender, EventArgs e)
{
ShipMethod.ConnectionString = ConfigurationSettings.AppSettings["DsnNorthwind"];
}//注意这儿
</script><body>
<form runat="server">
<strong>Here is some body text.</strong><P>Please choose a shipping method:
<wrox:shipment id="ShipMethod" runat="server" /></P></form>
</body>
</html>
还有种方法:
<wrox:shipment ConnectionString="server=localhost;uid=sa;pwd=;database=Northwind" runat="server" />
即:把ConnectionString和值放入wrox:shipment用户控件中作为属性