简单控件
文本类:
Label——显示文字
边框
要设置:1.边框颜色2.边框样式3.边框粗细
属性:BackColor
BorderColor/BorderStyle/BorderWidth ——设置边框
Literal ——作用也是显示文字,编译后不会形成任何元素
一般被用来输出JS代码
TextBox:文字输入框
属性:TextMode——MultLine 多行 (文本域)被编译后是Textarea
Password单行密码框
singleline 单行文本框
wrap——自动换行
enable ——是否可用
readonly——只读
maxlength最大长度,用来限制用户输入字符数
按钮类:
button按钮,被编译后为submit
<input type="submit" name="Button1" value="Button" id="Button1" />
OnclientClick:在服务端上的点击事件,编译为click
confirm ——验证判断
ImageButton——图片按钮
ImageUrl属性指定image图片地址
LinkButton——超链接
Hyperlink——超链接样式按钮
------------------------------------------------------
登陆:
webform的数据库连接方式——没有命名空间
类要添加到App_Code中
委托:
加载事件中:
Button1.Click += Button1_Click;
void Button1_Click(object sender, EventArgs e) { string Uname = TextBox1.Text; string Pwd = TextBox2.Text; bool isok = new UserDA().Select(Uname,Pwd); if (isok) Literal1.Text = "<script>alert('登陆成功')</script>"; else Literal1.Text = "<script>alert('登陆失败')</script>"; }
数据访问类:
public class UserDA { SqlConnection conn = null; SqlCommand cmd = null; public UserDA() { conn = new SqlConnection("server=.;database=Data0617;user=sa;pwd=123"); cmd = conn.CreateCommand(); } /// <summary> /// 用户验证 /// </summary> /// <param name="Username">验证用户名</param> /// <param name="Pwd">验证密码</param> /// <returns></returns> public bool Select(string Username, string Pwd) { bool has = false; cmd.CommandText = "select * from Users where Username=@user and Password=@pwd"; cmd.Parameters.Clear(); cmd.Parameters.AddWithValue("@user", Username); cmd.Parameters.AddWithValue("@pwd", Pwd); conn.Open(); SqlDataReader dr = cmd.ExecuteReader(); if (dr.HasRows) { has = true; } conn.Close(); return has; }
——————————————————————————————————————————
复合控件:
name:是给服务端用的
Id:是给客户端用的
DropDownList——编译成Select option
一、将数据放进去
<asp:DropDownList ID="DropDownList1" runat="server"> </asp:DropDownList>
<asp:Button ID="Button1" runat="server" Text="按钮1" />
<asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
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) { //第一种绑定方式: //DropDownList1.DataSource = new NationData().Select();//数据源指向 //DropDownList1.DataTextField = "NationName";//显示字段绑定 //DropDownList1.DataValueField = "NationCode";//隐藏字段绑定 //DropDownList1.DataBind(); //第二种绑定方式: if (!IsPostBack) { List<Nation> Nlist = new NationData().Select(); foreach (Nation n in Nlist) { ListItem li = new ListItem(n.NationName, n.NationCode); if (li.Value == "N003") { li.Selected = true; } RadioButtonList1.Items.Add(li); } } Button1.Click += Button1_Click;//按钮1点击事件 } void Button1_Click(object sender, EventArgs e) { string end = ""; foreach (ListItem li in RadioButtonList1.Items) { if (li.Selected) { end += li.Text + " - " + li.Value + ","; } } Label1.Text = end; } }
ListBox
可以多选 - SelectionMode
RadioButtonList
CheckBoxList
RepeatDirection="Horizontal" 横向排列, Vertical 纵向排列
RepeatColumns="3" 一行排3个
RepeatLayout="UnorderedList 无序
RepeatLayout="OrderedList 有序
RepeatLayout="Flow" 流式布局, 编译后的是 span