绑定表达式
localhost
Page.DataBind();
只有在执行这个方法时才会对整个页面的绑定表达式进行计算
对整个页面数据进行绑定,效率较低
->只对其中有些控件进行针对性的计算
指定控件进行数据绑定
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
App_code代码目录(创建类,类的目录)
Student.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.UI.WebControls;
public partial class _Default:System.Web.UI.Page
{
internal int x=10;
internal string[] arr1={"111","2222","333"};
internal Student stu1=new Student()
{
No="01",
Name="1111"
};
internal List<Student> List1=new List<Student>
{
new Student{No="02",Name="22222"},
new Student{No="03",Name="33333"}
};
protected void Page_Load(object sender,EventArgs e)
{
Page.DataBind();
}
}
Default.aspx
<DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<meta http-equiv="Content-Type" context="text/html:charset="utf-8"/>
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Label ID="Label1" runat="server" Text='<%# x %>'></asp:Label>
<asp:Buttun ID="Button1" runat="server" Text="Button"/>
<br/>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<asp:DropDownList ID="DropDownList1" DataSourse='<%# %>'>
定义一个学生的对象,在创建对象的同时初始化
创建+初始化
数据源控件
treeview
DelectQuery
针对四种SQL语言
DataSet数据集
数据源控件
视图与数据库之间的桥梁
ConnectionString连接字符串
ConnectionString=“<%$ %>”
autoPostBack √
FilterExpression筛选表达式
SqlDataSourse1.FilterExpression=“city=‘上海’”;
S DropdownList1.SelectedValue
DropDownList &数据源控件
可实现动态查询功能
> 大于
< 小于