一、注册
1、日期
(1)年月日用三DropDownList个,分别循环写入数字
代码写在后台
Page_Load中的代码
if (IsPostBack == false)
{
//年绑定数据 for (int i = DateTime.Now.Year; i >= 1900; i--) { ListItem li = new ListItem(i.ToString()); DropDownList5.Items.Add(li); } //月绑定数据 for (int i = 1; i <= 12; i++) { ListItem li = new ListItem(i.ToString()); DropDownList6.Items.Add(li); } //日绑定数据 rizi();}
//年改变事件
DropDownList5.SelectedIndexChanged += DropDownList5_SelectedIndexChanged;
//月改变事件
DropDownList6.SelectedIndexChanged += DropDownList6_SelectedIndexChanged;
//日绑定数据函数 private void rizi() { int m = Convert.ToInt32(DropDownList6.SelectedValue); int mm = Convert.ToInt32(DropDownList5.SelectedValue); int rq = new panriqi().riqi(m, mm); for (int i = 1; i <= rq; i++) { ListItem li = new ListItem(i.ToString()); DropDownList7.Items.Add(li); } } //年改变事件 void DropDownList5_SelectedIndexChanged(object sender, EventArgs e) { rizi(); } //月改变事件 void DropDownList6_SelectedIndexChanged(object sender, EventArgs e) { rizi(); }
调用的类
public int riqi(int m,int mm) //传入年和月 { int ri=0; if (m == 1 || m == 3 || m == 5 || m == 7 || m == 8 || m == 10 || m == 12) { ri = 31; } else if (m == 4 || m == 6 || m == 9 || m == 11) { ri = 30; } else if (m == 2) { if (mm % 4 == 0 && mm % 100 != 0 || mm % 400 == 0) { ri = 29; } else { ri = 28; } } return ri; }
(2)年月日取值
string s = DropDownList5.SelectedValue + "-" + DropDownList6.SelectedValue + "-" + DropDownList7.SelectedValue; u.Birthday = Convert.ToDateTime(s);
2、水印 placeHolder
3、JS验证
//验证用户名var duname = false; document.getElementById("TextBox1").onblur = function () { if (document.getElementById("TextBox1").value == "") { document.getElementById("Label1").innerText = "不能为空!"; } else { duname = true; document.getElementById("Label1").innerText = ""; } }
//注册按钮document.getElementById("Button1").onclick = function () { if (!duname || !dupwd || !dupwd2 || !dunicheng || !dup || !duyou || !duyz) { alert("请确认是否全部填写正确!"); return false;//后面的代码不执行 }
4、三级联动
(1)修改一个属性:AutoPostBack
二、Repeater重复器
四个模板:
HeaderTemplate: 在加载开始执行一遍
ItemTemplate : 有多少条数据,执行多少遍
FooterTemplate :在加载最后执行一遍
AlternatingItemTemplate : 交替项模板
1、用table展示数据库中的数据
<asp:Repeater ID="Repeater1" runat="server"> <HeaderTemplate>//头模板 <table id="tb1"> //标题 <tr id="tr_head"> <td>用户名</td> <td>密 码</td> <td>昵称</td> <td>性别</td> <td>出生日期</td> <td>年龄</td> <td>电话</td> <td>邮箱</td> <td>民族</td> <td>地区</td> </tr> </HeaderTemplate> <ItemTemplate>//项模板 <tr class="tr_item" style="<%#Eval("red") %>">//red标红 <td><%#Eval("UserName") %></td> <td><%#Eval("PassWord") %></td> <td><%#Eval("NickName") %></td> <td><%#Eval("sexstr ") %></td> <td><%#Eval("bir") %></td> <td><%#Eval("Age") %></td> <td><%#Eval("Phone") %></td> <td><%#Eval("Email") %></td> <td><%#Eval("nationstr") %></td> <td><%#Eval("Areastr") %></td> </tr> </ItemTemplate> <FooterTemplate>//尾模板 </table> </FooterTemplate> </asp:Repeater>
2、属性扩展在实体类中
3、标红(实体类中属性扩展)
//性别为女标红public string red { get { if(!_Sex) { return "background-color: red;"; } else { return ""; } } }
4、光棒效果(JS)
window.onload = function () { var oItems = document.getElementsByClassName("tr_item"); for (var i = 0; i < oItems.length; i++) { var oldColor = ""; oItems[i].onmouseover = function () {
//记录修改前的颜色
oldColor = this.style.backgroundColor;
this.style.backgroundColor = "yellow"; }; oItems[i].onmouseout = function () { this.style.backgroundColor = oldColor; }; }
时间: 2024-10-01 00:31:50