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 ...
随机推荐
- <c和指针>学习笔记1之快速上手和基本概念
1 c语言中的注释 功能:使这段代码在程序中不起作用,当然如果是功能注释,那是方便其他人阅读您的代码. 大部分情况下,多行的注释,我们采用的是这种方式,例如 /*内容*/. 这个符号不能嵌套,也就是 ...
- VNC协议分析
VNC协议分析 摘自: http://blog.csdn.net/forever_feng/article/details/4703088 简介 VNC(Virtual Network Computi ...
- 详解select()函数---
以后看 http://hi.baidu.com/bimufo/item/139700e4d880cba1c00d755c
- ADT-Bundle--Android开发环境快速搭建
http://blog.csdn.net/aizquan/article/details/8974750
- Flutter起步之安装
官网有介绍的这里就不说,主要有几个步骤: 镜像设置 下载flutter SDK(更新系统环境变量PATH,先不要运行flutter doctor,因为你还没有装android sdk和编辑器) and ...
- Kbengine
Kbengine 编辑 KBEngine是一款开源的游戏服务端引擎,使用简单的约定协议就能够使客户端与服务端进行交互, 使用KBEngine插件能够快速与(Unity3D, OGRE, Cocos2d ...
- cf808E(三分)
题目链接:http://codeforces.com/problemset/problem/808/E 题意:给出n个体积为wi, 价值为ci的物品,背包容量为m,求能容纳的最大物品价值,其中 1&l ...
- 洛谷P2280 [HNOI2003]激光炸弹
P2280 [HNOI2003]激光炸弹 题目描述 输入输出格式 输入格式: 输入文件名为input.txt 输入文件的第一行为正整数n和正整数R,接下来的n行每行有3个正整数,分别表示 xi,yi ...
- Python爬虫之设置selenium webdriver等待
Python爬虫之设置selenium webdriver等待 ajax技术出现使异步加载方式呈现数据的网站越来越多,当浏览器在加载页面时,页面上的元素可能并不是同时被加载完成,这给定位元素的定位增加 ...
- Continuous Integration
https://dzone.com/articles/continuous-delivery-toolchain