.jpg"); list.Add("3.jpg"); this.DropDownList1.DataSource = list; //指定数据源
this.DropDownList1.DataBind(); } 3、利用数据库操作进行动态的数据绑定(较为正规的用法) //利用数据库操作进行动态数据绑定 if (!IsPostBack) { stringstrConn = "server=LSC-BD9E16FDC63\\SQLEXPRESS;database=mldn;Uid=china;Pwd=1 2345678"; SqlConnectionsqlConn = new SqlConnection(strConn);
sqlConn.Open(); SqlCommandcmd = new SqlCommand(); cmd.CommandText = "select * from Images"; cmd.Connection =sqlConn; SqlDataAdaptersda = new SqlDataAdapter(cmd); DataTabledt = new DataTable(); sda.Fill(dt); this.DropDownList1.DataSource = dt; this.DropDownList1.DataTextField = "imgs"; 示给用户的数据 this.DropDownList1.DataValueField = "imgs"; 递给服务器的数据 this.DropDownList1.DataBind(); } 在 ASP.NET 中利用 onClientClick()事件调用
JavaScript 代码而不用 onClick() 事件 //添加传 //添加显
在代码后面添加 return false 阻止后面的代码执行 在判断文本框、 密码框等不能为空的判断时, 避免没有添加页面仍然跳转则在每一 个判断后面添加一上 return false, 同时在 onClientClick()中添加 return javaScript 方法
CheckBoxList 的用法: 的用法:
int count = this.CheckBoxList1.Items.Count; for (int index = 0; index <= count; index++) { if (this.CheckBoxList1.Items[index].Selected) { Response.Write(this.CheckBoxList1.Items[index].Text); } }
RadioButtonList 的用法: 的用法:
for (int index = 0; index < this.RadioButtonList1.Items.Count; index++) { if (this.RadioButtonList1.Items[index].Selected) { Response.Write(this.RadioButtonList1.Items[index].Text); } }
Data 中的 Repeater 的用法:主要用于分页 的用法:
首先拖动一个 Reoeater 控件,然后配置数据源 在切换到代码视图,添加相应的模板,其中()模板如下:
--必写
行的显示方式 对应实例:
ASP 中的分页: 中的分页: 真分页和假分页
假分页: using System; usingSystem.Collections.Generic; usingSystem.Linq; usingSystem.Web; usingSystem.Web.UI; usingSystem.Web.UI.WebControls; usingSystem.Data; usingSystem.Data.SqlClient; public partial class page : System.Web.UI.Page { privateintpageNumber = 0; privateintlineCount; public void pages() { stringstrConn = "server=LSC-BD9E16FDC63\\SQLEXPRESS;database=build;Pwd=12345678;U id=china"; SqlConnection conn = new SqlConnection(strConn); conn.Open(); SqlCommandcmd = new SqlCommand(); cmd.Connection = conn; cmd.CommandText = "select * from fangyuan"; SqlDataAdaptersda = new SqlDataAdapter(cmd); DataTabledt = new DataTable(); sda.Fill(dt); PagedDataSourcepds = new PagedDataSource();
pds.DataSource = dt.DefaultView; pds.AllowPaging = tr