当前位置: 编程技术>.net/c#/asp.net
本页文章导读:
▪asp.net 数据绑定的实例代码
代码如下:public partial class _Default : System.Web.UI.Page{ protected string title="大家好"; //前台代码<title><%#title %></title> protected void Page_Load(object sender, EventArgs e) .........
▪asp.Net JS取母板页控件值的简单方法
代码如下:<script type="text/javascript" language="javascript"> function Check() { var text = parent.document.getElementById('<%=HiddenField1.ClientID %>'); //如有母板页+pardent. ,普通取.........
▪.net 读取非标准配置文件的小例子
代码如下: 代码如下:public static string Config(string key) { ExeConfigurationFileMap file = new ExeConfigurationFileMap(); file.ExeConfigFilename = @"Providers\\Provider.config";.........
[1]asp.net 数据绑定的实例代码
来源: 互联网 发布时间: 2013-11-30
代码如下:
public partial class _Default : System.Web.UI.Page
{
protected string title="大家好"; //前台代码<title><%#title %></title>
protected void Page_Load(object sender, EventArgs e)
{
DataSet ds = new DataSet();
string sql = ConfigurationManager.ConnectionStrings["strsql"].ConnectionString;
using (SqlConnection sqlCnn=new SqlConnection(sql))
{
using (SqlCommand sqlCmm=sqlCnn.CreateCommand())
{
sqlCmm.CommandText = "select * from List";
SqlDataAdapter adapter = new SqlDataAdapter(sqlCmm);
adapter.Fill(ds);
}
this.RadioButtonList1.DataSource = ds.Tables[0];
this.RadioButtonList1.DataTextField = "listname";
this.RadioButtonList1.DataValueField = "id";
//this.RadioButtonList1.DataBind();
this.CheckBoxList1.DataSource = ds.Tables[0];
this.CheckBoxList1.DataTextField = "listname";
this.CheckBoxList1.DataValueField = "id";
//this.RadioButtonList1.DataBind();
this.DataBind();
} //数据绑定到RadioButtonList,CheckBoxList
if (!IsPostBack)
{
DataSet ds1 = new DataSet();
using (SqlConnection sqlCnn1 = new SqlConnection(sql))
{
using (SqlCommand sqlCmm1 = sqlCnn1.CreateCommand())
{
sqlCmm1.CommandText = "select provinceid,provincename from Province";
SqlDataAdapter adapter = new SqlDataAdapter(sqlCmm1);
adapter.Fill(ds1);
this.DropDownList1.DataSource = ds1.Tables[0];
this.DropDownList1.DataTextField = "provincename";
this.DropDownList1.DataValueField = "provinceid";
this.DropDownList1.DataBind();
}
}
}
}
protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{
DataSet ds = new DataSet();
string str = ConfigurationManager.ConnectionStrings["strsql"].ConnectionString;
using (SqlConnection sqlCnn = new SqlConnection(str))
{
using (SqlCommand sqlCmm = sqlCnn.CreateCommand())
{
sqlCmm.CommandText = "select cityid,cityname from City where provinceid='" + this.DropDownList1.SelectedValue + "'";
SqlDataAdapter adapter = new SqlDataAdapter(sqlCmm);
adapter.Fill(ds);
this.DropDownList2.DataSource = ds.Tables[0];
this.DropDownList2.DataTextField = "cityname";
this.DropDownList2.DataValueField = "cityid";
this.DropDownList2.DataBind();
}
}
}//实现省市二级联动
}
[2]asp.Net JS取母板页控件值的简单方法
来源: 互联网 发布时间: 2013-11-30
代码如下:
<script type="text/javascript" language="javascript">
function Check() {
var text = parent.document.getElementById('<%=HiddenField1.ClientID %>'); //如有母板页+pardent. ,普通取值不用加
if (confirm("您已运输" + text.value + "台")) {
return true;
}
else {
return false;
}
}
</script>
[3].net 读取非标准配置文件的小例子
来源: 互联网 发布时间: 2013-11-30
代码如下:
public static string Config(string key)
{
ExeConfigurationFileMap file = new ExeConfigurationFileMap();
file.ExeConfigFilename = @"Providers\\Provider.config";
Configuration config = ConfigurationManager.OpenMappedExeConfiguration(file, ConfigurationUserLevel.None);
AppSettingsSection appsection = (AppSettingsSection)config.GetSection("appSettings");
return appsection.Settings[key].Value;
}
配置文件目录结构:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<appSettings>
<add key="ConnectionString" value="Server=(local);Database=DB;User Id=sa;Password=123" />
</appSettings>
</configuration>
调用:
//里面的参数为配置文件的key
string strConn=Config("ConnectionString");
代码如下:
public static string Config(string key)
{
ExeConfigurationFileMap file = new ExeConfigurationFileMap();
file.ExeConfigFilename = @"Providers\\Provider.config";
Configuration config = ConfigurationManager.OpenMappedExeConfiguration(file, ConfigurationUserLevel.None);
AppSettingsSection appsection = (AppSettingsSection)config.GetSection("appSettings");
return appsection.Settings[key].Value;
}
配置文件目录结构:
代码如下:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<appSettings>
<add key="ConnectionString" value="Server=(local);Database=DB;User Id=sa;Password=123" />
</appSettings>
</configuration>
调用:
代码如下:
//里面的参数为配置文件的key
string strConn=Config("ConnectionString");
最新技术文章: