<%@ %> - 这里面写一些声明和引用的
<% %> - 编写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. [hdu4405]Aeroplane chess(概率dp)

    题意:某人掷骰子,数轴上前进相应的步数,会有瞬移的情况,求从0到N所需要的期望投掷次数. 解题关键:期望dp的套路解法,一个状态可以转化为6个状态,则该状态的期望,可以由6个状态转化而来.再加上两个状 ...

  2. mysql Split函数

    mysql没有split函数,这里手动写一个: ),)) BEGIN CREATE TEMPORARY TABLE IF NOT EXISTS temp_split ( col ) ); DELETE ...

  3. iframe和window对象的关系

    浏览器会在其打开一个 HTML 文档时创建一个对应的 window 对象.但是,如果一个文档定义了一个或多个框架(即,包含一个或多个 frame 或 iframe 标签),浏览器就会为原始文档创建一个 ...

  4. Ajax的调试错误信息的输出

    error: function(xhr, status, error) { console.log(xhr); console.log(status); console.log(error); }

  5. C#——传值参数(3)

    上篇文章我与大家共同学习了 值参数——引用类型这次与大家共同学习 传值参数--引用类型,不创建新对象,只操作对象这是个思维导图:我们仍需记住:1.值参数创建变量的副本 2.对值参数的改变不会影响变量的 ...

  6. ugui获取text宽

    http://www.xuanyusong.com/archives/3587 void Start () { Font font = Resources.Load<Font>(" ...

  7. 在Visual Studio中编译Linux的一些问题

    相对路径: 在windows下,和当前文件同一个目录下的引用会这么写: #include "SubDirectory\header.h" 或者 #include "Sub ...

  8. try catch finally的执行顺序学习

    try catch finally的执行顺序学习   首先执行try,如果有异常执行catch,无论如何都会执行finally,当有return以后,函数就会把这个数据存储在某个位置,然后告诉主函数, ...

  9. 11.Python初窥门径(函数名,可迭代对象,迭代器)

    Python(函数名,可迭代对象,迭代器) 一.默认参数的坑 # 比较特殊,正常来说临时空间执行结束后应该删除,但在这里不是. def func(a,l=[]): l.append(a) return ...

  10. shell学习(9)- du和df区别及详解

    清明小长假来加班,总得干点啥吧,今天就说说du 和df的区别. 1.区别 du,disk usage,是通过搜索文件来计算每个文件的大小然后累加,du能看到的文件只是一些当前存在的,没有删除的.他计算 ...