- 创建UI层使用类库
- 创建.aspx界面
- 显示控件
DropDownList控件(下拉框):
使用选择数据源为DropDownList控件绑定数据
删除 DataSource模块 和DataSourceID属性
在后台Page_Load方法内 使用if (!IsPostBack)
然后在if内使用DropDownList1.DataSource=BLL层的查找方法
最后使用DropDownList1.DataBind(); 绑定
if (!IsPostBack) { DropDownList1.DataSource = ProTypeManage.Select(); DropDownList1.DataBind(); }
如果要为DropDownList控件添加不存在查找的选项 在编辑项里添加 Selected 为默认选中
然后使用AppendDataBoundItems="true" 来保留添加的新项
GridView控件(数据):
使用选择数据源为GridView控件绑定数据
删除DataSourceID属性和生成的SqlDataSource控件
配置完后编辑列 隐藏多余的字段 Visible=false
然后在后台 绑定数据源:GridView.DataSource=BLL.Manage.Select(); 执行数据绑定:GridView.DataBind();
GridView1.DataSource = ProInfoManage.Select(); GridView1.DataBind();
使用指定数据显示
使用模板列 一般使用Label控件 Text='<%# Convert.ToString(Eval("基准列"))==1?"基准值" :"基准值"%>'
Text='<%#Convert.ToInt32(Eval("Istop"))==1?"推荐":"不推荐" %>'>
使用隐藏指定控件
visible='<%# Convert.ToString(Eval("基准列"))=="基准值" %>'
控件ID.Visible=false;
Visible='<%#Convert.ToInt32(Eval("TaskState"))==1 %>' />