web端 repeat和简单控件
<%@ %> - 这里面写一些声明和引用的
<% %> - 编写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和简单控件的更多相关文章
- WebForm--j简单控件、简单的登录(怎么链接数据库)
一.简单控件 1.label:边框(边框的颜色.样式.粗细) 是专门显示文字的, 被编译后是 <span id="Label1">Label</spa ...
- WebForm 简单控件、复合控件
简单控件: Label:被编译成span 样式表里设置lable的高度: display:inline-block; Text --文本 ForeColor --字体颜色 Visible -- ...
- Webform(简单控件、复合控件)
一.简单控件: 1.label控件 <asp:Label ID="Label1" runat="server" Text="账 号:" ...
- 五:理解控件的运行机制(例:基于Control命名空间的简单控件)
一:先用最简短的话说点理论的1.asp.net中所有的标准控件都可以重写 2.和控件相关的命名空间有 System.Web.UI.Control是所有控件的基类只提供简单的呈现逻辑,不支持样式表 Sy ...
- 2013 duilib入门简明教程 -- 简单控件介绍 (12)
前面的教程应该让大家对duilib的整体有所映像了,下面就来介绍下duilib具体控件的使用. 由于官方没有提供默认的控件样式,所以我就尽量使用win7或者XP自带的按钮样式了,虽然界 ...
- WebForm简单控件,复合控件
简单控件: 1.Label 会被编译成span标签 属性: Text:文本内容 CssClass:CSS样式 Enlabled:是否可用 Visible:是否可见 __________________ ...
- Button,CheckBox,Lable,RadioButton,ComboBox,TextBox六个简单控件的使用
所有文字的更改全部在Text属性中更改! ComboBox:点击右上方小箭头,选择编辑项弹出: RadioButton:,Checked属性选择True,表示已被选中: Button:在设计中双击按钮 ...
- webform简单控件
表单元素: 文本类: text password textarea hidden text,password,textarea实现控件:textbox textmode属性选择password或m ...
- weborm 简单控件
Label - 显示文字,编译后是spanLiteral - 显示文字,编译后没有形成元素 只是文字 一般用来输出 js代码内容 TextBox - 文本框 TextMode -普通文本框 singl ...
随机推荐
- JS极品日历
<!DOCTYPE><html><head><meta http-equiv="Content-Type" content="t ...
- 【机器学习】随机森林RF
随机森林(RF, RandomForest)包含多个决策树的分类器,并且其输出的类别是由个别树输出的类别的众数而定.通过自助法(boot-strap)重采样技术,不断生成训练样本和测试样本,由训练样本 ...
- linux下的函数dirname()和basename()使用
总览 #include <libgen.h> char *dirname(char *path); char *basename(char *path); 说明 函数以 '/' 为分隔符 ...
- Umbraco examine search media folder 中的pdf文件
可以参考的文章 http://sleslie.me/2015/selecting-media-using-razor-slow-performance-examine-to-the-rescue/ h ...
- Java socket异常
Java socket异常 分类: Java 2013-07-15 22:38 981人阅读 评论(0) 收藏 举报 目录(?)[+] 使用Java socket编写程序时,通常会遇到几种种异常:Bi ...
- c++中调用python脚本提示 error LNK2001: 无法解析的外部符号 __imp_Py_Initialize等错误的解决方法
最近项目中需要实现一个服务器宕机后短信提醒的功能,个人觉得在使用Python 写http请求这块很方便,发短信这块就使用了python,但是c++程序中调用这个脚本时,编译不通过,提示如下错误: er ...
- Python中生成随机数
目录 1. random模块 1.1 设置随机种子 1.2 random模块中的方法 1.3 使用:生成整形随机数 1.3 使用:生成序列随机数 1.4 使用:生成随机实值分布 2. numpy.ra ...
- org.apache.commons.httpclient.HttpClient的使用(转)
HTTP 协议可能是现在 Internet 上使用得最多.最重要的协议了,越来越多的 Java 应用程序需要直接通过 HTTP 协议来访问网络资源.虽然在 JDK 的 java net包中已经提供了访 ...
- luogu P2570 [ZJOI2010]贪吃的老鼠【二分+最大流】
首先考虑只满足第一个条件,二分答案,把过期时间加上mid之后的2n个时间离散,老鼠拆成每个时间的,第i个时间第j个老鼠为id[i][j],连接(s,i,p[i]),对于离散后时间(g[j-1]~g[j ...
- 剑指Offer的学习笔记(C#篇)-- 二叉树的下一个节点(好理解版本)
题目描述 给定一个二叉树和其中的一个结点,请找出中序遍历顺序的下一个结点并且返回.注意,树中的结点不仅包含左右子结点,同时包含指向父结点的指针. 一 . 理解题意 该题目我们可以借鉴一个非常影响不好的 ...