<%@ %> - 这里面写一些声明和引用的
<% %> - 编写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. c# link 学习网站

    http://www.cnblogs.com/shanyou/p/4353433.html

  2. [hdu3586]Information Disturbing树形dp+二分

    题意:给出一棵带权无向树,以及给定节点1,总约束为$m$,找出切断与所有叶子节点联系每条边所需要的最小价值约束. 解题关键:二分答案,转化为判定性问题,然后用树形dp验证答案即可. dp数组需要开到l ...

  3. Eclipse&nbsp;安装插件

    Eclipse 安装插件 本文介绍Eclipse插件的安装方法.Eclipse插件的安装方法大体有三种:直接复制.使用link文件,以及使用eclipse自带的图形界面的插件安装方法. AD: 做为当 ...

  4. 干货:SEO长尾关键词优化方法和技巧

    在网站SEO优化上,优化比较成功的网站,根据SEO界前辈的经验结论,网站的总流量主要来源于长尾关键词,占网站总流量的80%.长尾关键词主要分布在网站的文章页,其次就是栏目页title.标签页.专题页等 ...

  5. Laravel框架的一些配置

    服务器的配置 1.在apache下的配置 配置httpd-conf:php5_module.rewrite_module.Listen 配置extra/httpd-vhost:端口.站点.域名.默认首 ...

  6. NOIP2015提高组 跳石头 ACM-ICPC2017香港 E(选择/移除+二分答案)

    跳石头 题目背景 一年一度的“跳石头”比赛又要开始了! 题目描述 这项比赛将在一条笔直的河道中进行,河道中分布着一些巨大岩石.组委会已经选择好了两块岩石作为比赛起点和终点.在起点和终点之间,有 NN  ...

  7. ASP.NET学习笔记(四)CDOSYS邮件

    使用 CDOSYS 发送电子邮件 CDO (Collaboration Data Objects) 是一项微软的技术,设计目的是用来简化通信程序的创建. CDOSYS 是 ASP 中的内置组件.我们会 ...

  8. 给Fitnesse添加调用多参数fixture的调用方法

    修改文件:fitnesse.slim.fixtureInteraction.DefaultInteraction.java 修改如下三处内容: (注意只支持仅含有一个参数,且该参数是多参数的fixtu ...

  9. ORM应用

    目录 ORM概念 ORM由来 ORM的优势 ORM的劣势 ORM总结 ORM 与 DB 的对应关系图 Model 模块 ORM操作 增删改查操作 ORM概念 对象关系映射(Object Relatio ...

  10. 从图(Graph)到图卷积(Graph Convolution):漫谈图神经网络模型 (二)

    本文属于图神经网络的系列文章,文章目录如下: 从图(Graph)到图卷积(Graph Convolution):漫谈图神经网络模型 (一) 从图(Graph)到图卷积(Graph Convolutio ...