<%@ %> - 这里面写一些声明和引用的
<% %> - 编写C#代码的
<%= %>
<%# %>

Repeater - 重复器     相当于winform的listview
HeaderTemplate - 先执行,执行一次
FooterTemplate - 最后执行,执行一次
ItemTemplate - 在Header之后执行,有多少条数据绑定就执行多少次

AlterNatingItemTemplate - 交替项模板,与ItemTemplate交替执行

<%# Eval("属性名","可选,格式字符串") %>
<%# 方法名() %>

绑定数据

List<Users> ulist=new UsersData().SelectAll();

Repeat1.datasource=ulist;  //数据源是ulist

Reapeat1.Bind();    数据绑定

展示使用

<%#Eval("属性名")   %>

例如:

封装类

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web; /// <summary>
/// Users 的摘要说明
/// </summary>
public class Users
{
public int Ids { get; set; }
public string UserName { get; set; }
public string Password { get; set; }
public string NickName { get; set; }
public bool Sex { get; set; }
public string Sexstr
{
get { return Sex ? "男" : "女"; }
}
public DateTime BirthDay { get; set; }
public int Age { get { return DateTime.Now.Year - BirthDay.Year; } }
public string Nation { get; set; }
public string NationName { get { return new UsersData().SelectNationName(Nation); }
}
}

封装方法

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data.SqlClient;
/// <summary>
/// UsersData 的摘要说明
/// </summary>
public class UsersData
{
SqlConnection conn = null;
SqlCommand cmd = null;
public UsersData()
{
conn = new SqlConnection("server=.;database=dat0216;user=sa;pwd=123;");
cmd = conn.CreateCommand();
}
public List<Users> SelectAll()
{
List<Users> ulist = new List<Users>();
cmd.CommandText = "select *from Users";
conn.Open();
SqlDataReader dr = cmd.ExecuteReader();
while (dr.Read())
{
Users u = new Users();
u.Ids = Convert.ToInt32(dr[]);
u.UserName = dr[].ToString();
u.Password = dr[].ToString();
u.NickName = dr[].ToString();
u.Sex = Convert.ToBoolean(dr[]);
u.BirthDay = Convert.ToDateTime(dr[]);
u.Nation = dr[].ToString();
ulist.Add(u);
}
conn.Close();
return ulist;
} public string SelectNationName(string code)
{
string end = "<暂无>";
cmd.CommandText = "select *from Nation where NationCode=@a";
cmd.Parameters.Clear();
cmd.Parameters.Add("@a",code);
conn.Open();
SqlDataReader dr = cmd.ExecuteReader();
if (dr.HasRows)
{
dr.Read();
end = dr["NationName"].ToString();
}
conn.Close();
return end;
} public bool HasUserName(string name)
{
bool IsName = false;
cmd.CommandText = "select *from Users where UserName=@a";
cmd.Parameters.Clear();
cmd.Parameters.Add("@a",name);
conn.Open();
SqlDataReader dr = cmd.ExecuteReader();
if (dr.HasRows)
{
dr.Read();
IsName = true;
}
conn.Close();
return IsName;
}
}

绑定数据

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls; public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
Repeater1.DataSource = new UsersData().SelectAll();
Repeater1.DataBind();
}
}

展示数据

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title></title>
<link href="CSS/StyleSheet.css" rel="stylesheet" />
</head>
<body>
<form id="form1" runat="server">
<div style="width: 100%;">
<div class="div1">
<div id="div1"> <a href="Default2.aspx" target="_blank">注册页面</a>
</div>
<asp:Repeater ID="Repeater1" runat="server">
<HeaderTemplate>
<table class="table1">
<tr class="tr1">
<td>编号</td>
<td>用户名</td>
<td>密码</td>
<td>昵称</td>
<td>性别</td>
<td>生日</td>
<td>年龄</td>
<td>民族</td>
</tr>
</HeaderTemplate>
<ItemTemplate>
<tr class="tr2">
<td><%#Eval("Ids") %></td>
<td><%#Eval("UserName") %></td>
<td><%#Eval("PassWord") %></td>
<td><%#Eval("NickName") %></td>
<td><%#Eval("Sexstr") %></td>
<td><%#Eval("Birthday") %></td>
<td><%#Eval("Age") %></td>
<td><%#Eval("NationName") %></td>
<td></td>
</tr>
</ItemTemplate>
<FooterTemplate>
</table>
</FooterTemplate>
</asp:Repeater>
</div>
</div>
</form>
</body>
</html>

样式表

.div1 {
width:%;
margin-left:%;
background-color:pink;
}
.table1 {
background-color:navy;
text-align:center;
} .tr1 {
font-size:30px;
color:white;
}
.tr2 {
background-color:white;
}
#div1 {
margin-right:%; }

假设 我要把年龄大于16 的数据   背景色改为红色

先把背景色  写好  style=" background-color: white";

在写在封装类中

public string WhiteOrRed

{

get{int Age>16?"red":"white";}

}

在把style样式改为 style="background-color:<% #Eval("WhiteOrRed") %>  ;  ";

或者修改性别 插入性别图片也是如此;

常用控件

简单控件

label   控件

使用控件的代码

<asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>

启用网页 看到的代码是

<span id="Label1">Label</span>

也就是说label  相当于  span

不过span  里内容多大 就显示多大  要占用多大空间

样式表要写:display:inline-block;

1.lateral 控件

网页和网页代码都是显示   lateral   text的内容

所以有时候可以这么写

lateral1.text="<script>alert("要弹出的内容");</script>";

2.button控件

相当于html的  submit

使用控件的代码

<asp:Button ID="Button1" runat="server" Text="Button" />

转意网页的代码

<input type="submit" name="Button1" value="Button" id="Button1" />

3.TextBox - TextMode
SingLine - type="text"
PassWord - type="password"
MultiLine - <textarea>

4.HiddenField - type="hidden"

5.Button - submit
6.ImageButton - type="image"

<asp:ImageButton ID="ImageButton1" runat="server"  ImageUrl="images/0.png"/>   图片路径

web端 repeat和简单控件的更多相关文章

  1. WebForm--j简单控件、简单的登录(怎么链接数据库)

    一.简单控件 1.label:边框(边框的颜色.样式.粗细)  是专门显示文字的,   被编译后是    <span id="Label1">Label</spa ...

  2. WebForm 简单控件、复合控件

    简单控件: Label:被编译成span 样式表里设置lable的高度:  display:inline-block; Text  --文本 ForeColor  --字体颜色 Visible  -- ...

  3. Webform(简单控件、复合控件)

    一.简单控件: 1.label控件 <asp:Label ID="Label1" runat="server" Text="账 号:" ...

  4. 五:理解控件的运行机制(例:基于Control命名空间的简单控件)

    一:先用最简短的话说点理论的1.asp.net中所有的标准控件都可以重写 2.和控件相关的命名空间有 System.Web.UI.Control是所有控件的基类只提供简单的呈现逻辑,不支持样式表 Sy ...

  5. 2013 duilib入门简明教程 -- 简单控件介绍 (12)

        前面的教程应该让大家对duilib的整体有所映像了,下面就来介绍下duilib具体控件的使用.     由于官方没有提供默认的控件样式,所以我就尽量使用win7或者XP自带的按钮样式了,虽然界 ...

  6. WebForm简单控件,复合控件

    简单控件: 1.Label 会被编译成span标签 属性: Text:文本内容 CssClass:CSS样式 Enlabled:是否可用 Visible:是否可见 __________________ ...

  7. Button,CheckBox,Lable,RadioButton,ComboBox,TextBox六个简单控件的使用

    所有文字的更改全部在Text属性中更改! ComboBox:点击右上方小箭头,选择编辑项弹出: RadioButton:,Checked属性选择True,表示已被选中: Button:在设计中双击按钮 ...

  8. webform简单控件

    表单元素: 文本类: text password textarea hidden text,password,textarea实现控件:textbox   textmode属性选择password或m ...

  9. weborm 简单控件

    Label - 显示文字,编译后是spanLiteral - 显示文字,编译后没有形成元素 只是文字 一般用来输出 js代码内容 TextBox - 文本框 TextMode -普通文本框 singl ...

随机推荐

  1. Java 打包成exe安装包

    1.在eclipse中导出Runnable JAR file 2.选择主函数所在的类和输出位置后finish: 3.这里选择的打包工具是exe4j,在网上找序列号注册一下,否则在打完后在exe运行时, ...

  2. <正则吃饺子> :关于微信支付的简单总结说明(二)

    关于微信退款 一.官方文档 申请退款:https://pay.weixin.qq.com/wiki/doc/api/app/app.php?chapter=9_4&index=6 二.退款流程 ...

  3. 【242】◀▶IEW-Unit07

    Unit 7 Education: Schools I.句子基本结构在写作中的运用 主谓宾 主系表 主谓 主谓宾宾 主谓宾补 1.主语: 1)位于句首 2)名词 例句:应该建立相关法律 Laws an ...

  4. day11会话管理

    会话管理入门 2.1 生活中会话 我: 小张,你会跳小苹果码? 小张: 会,怎么了? 我: 公司年会上要表演节目,你教教我把 小张:没问题,一顿饭而已. 我: OK. ........ 在这次生活中的 ...

  5. FZU 2057 家谱(dfs)

    Problem 2057 家谱 Accept: 129    Submit: 356Time Limit: 1000 mSec    Memory Limit : 32768 KB  Problem ...

  6. ZOJ 3512 Financial Fraud (左偏树)

    题意:给定一个序列,求另一个不递减序列,使得Abs(bi - ai) 和最小. 析:首先是在每个相同的区间中,中位数是最优的,然后由于要合并,和维护中位数,所以我们选用左偏树来维护,当然也可以用划分树 ...

  7. 使用的SQLServer版本不支持数据类型“datetime2“

    快速解决方法: 原因,在使用ado.net entity的时候,entity使用的数据库是sqlserver 2008, 但后来实际使用中使用的数据库是sqlserver 2005, 操作DateTi ...

  8. unity5 manifest

    https://www.cnblogs.com/lancidie/p/5878789.html 之前曾经写了一篇博客介绍Unity5的AssetBundle,结果似乎很受关注.不过似乎很多人看了之后都 ...

  9. SpringBoot进阶教程(五十九)整合Codis

    上一篇博文<详解Codis安装与部署>中,详细介绍了codis的安装与部署,这篇文章主要介绍介绍springboot整合codis.如果之前看过<SpringBoot进阶教程(五十二 ...

  10. Beanshell vs JSR223 vs Java JMeter脚本:性能关闭你一直在等待!

    有几个选项可用于执行自定义JMeter脚本并扩展基线JMeter功能.查看最流行的扩展机制,比较性能并分析哪一个是最好的. 这是乐队之战,JMeter风格. Beanshell V. JSR223 V ...