绝想首页

DropDownList 应用

爱嘉人 [无奈] 2013-03-15 17:59:44 星期五 晴天 查看:94 回复:0 发消息给作者

void Page_Load(object sender, System.EventArgs e)

{ if(!IsPostBack) {

// 创建数据库连接字符串和SQL语句

string ConnStr = System.Configuration.ConfigurationSettings.AppSettings["ConnectionSqlServer"];

string query = "SELECT * FROM Products";

// 执行数据库语句并填充数据到 DataTable 中

SqlCommand myCommand = new SqlCommand(query, new SqlConnection(ConnStr));

SqlDataAdapter myAdapter = new SqlDataAdapter(myCommand);

DataTable dt = new DataTable(); myAdapter.Fill(dt);

// 数据绑定 DropDownList 控件

DropDownList1.DataSource = dt;

DropDownList1.DataTextField = "ProductName"; DropDownList1.DataValueField = "ProductName";

DropDownList1.DataBind(); } }

void DropDownList1_SelectedIndexChanged(object sender, System.EventArgs e)

{ Label1.Text = "UnitPrice: " + DropDownList1.SelectedValue; } void Page_Load(object sender, System.EventArgs e) { if(!IsPostBack) { // 创建数据库连接字符串和SQL语句 string ConnStr = System.Configuration.ConfigurationSettings.AppSettings["ConnectionSqlServer"]; string query = "SELECT * FROM Products"; // 执行数据库语句并填充数据到 DataTable 中 SqlCommand myCommand = new SqlCommand(query, new SqlConnection(ConnStr)); SqlDataAdapter myAdapter = new SqlDataAdapter(myCommand); DataTable dt = new DataTable(); myAdapter.Fill(dt); // 数据绑定 DropDownList 控件 DropDownList1.DataSource = dt; DropDownList1.DataTextField = "ProductName"; DropDownList1.DataValueField = "ProductName"; DropDownList1.DataBind(); } } void DropDownList1_SelectedIndexChanged(object sender, System.EventArgs e) { Label1.Text = "UnitPrice: " + DropDownList1.SelectedValue; } void Page_Load(object sender, System.EventArgs e) { if(!IsPostBack) { // 创建数据库连接字符串和SQL语句 string ConnStr = System.Configuration.ConfigurationSettings.AppSettings["ConnectionSqlServer"]; string query = "SELECT * FROM Products"; // 执行数据库语句并填充数据到 DataTable 中 SqlCommand myCommand = new SqlCommand(query, new SqlConnection(ConnStr)); SqlDataAdapter myAdapter = new SqlDataAdapter(myCommand); DataTable dt = new DataTable(); myAdapter.Fill(dt); // 数据绑定 DropDownList 控件 DropDownList1.DataSource = dt; DropDownList1.DataTextField = "ProductName"; DropDownList1.DataValueField = "ProductName"; DropDownList1.DataBind(); } } void DropDownList1_SelectedIndexChanged(object sender, System.EventArgs e) { Label1.Text = "UnitPrice: " + DropDownList1.SelectedValue; } void Page_Load(object sender, System.EventArgs e) { if(!IsPostBack) { // 创建数据库连接字符串和SQL语句 string ConnStr = System.Configuration.ConfigurationSettings.AppSettings["ConnectionSqlServer"]; string query = "SELECT * FROM Products"; // 执行数据库语句并填充数据到 DataTable 中 SqlCommand myCommand = new SqlCommand(query, new SqlConnection(ConnStr)); SqlDataAdapter myAdapter = new SqlDataAdapter(myCommand); DataTable dt = new DataTable(); myAdapter.Fill(dt); // 数据绑定 DropDownList 控件 DropDownList1.DataSource = dt; DropDownList1.DataTextField = "ProductName"; DropDownList1.DataValueField = "ProductName"; DropDownList1.DataBind(); } } void DropDownList1_SelectedIndexChanged(object sender, System.EventArgs e) { Label1.Text = "UnitPrice: " + DropDownList1.SelectedValue; }

顶一下(33 写日记 1219970 234556
分享排行

 

 

留住已经逝去的峥嵘岁月 记住曾经绽现的万种风情 在记忆即将淡漠的时候 来把这些重新回味

Copyright (C) 2008-2014 www.juexiang.com, All Rights Reserved.

京ICP备2023001011号-3   京公网安备11010802011908号

客服QQ 1017160561 违法和不良信息举报电话 13148464312 邮箱 1017160561@qq.com