简单控件文本类:Label——显示文字边框要设置:1.边框颜色2.边框样式3.边框粗细属性:BackColorBorderColor/BorderStyle/BorderWidth ——设置边框Literal ——作用也是显示文字,编译后不会形成任何元素一般被用来输出JS代码TextBox:文字输入框属性:TextMode——MultLine 多行 (文本域)被编译后是Textarea Password单行密码框 singleline 单行文本框wrap——自动换行enable ——是否可用 readonly——只读maxlength最大长度,用来限制用户输入字符数 按钮类:button按钮,被编译后为submitOnclientClick:在服务端上的点击事件,编译为clickconfirm ——验证判断 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 = “”;
}数据访问类:public class UserDA
{
SqlConnection conn = null;
SqlCommand cmd = null;
public UserDA()
{
conn = new SqlConnection(“server=.;database=Data0617;user=sa;pwd=123”);
cmd = conn.CreateCommand();
}
///
/// 用户验证
///
/// 验证用户名
/// 验证密码
///
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
一、将数据放进去
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 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
RadioButtonListCheckBoxListRepeatDirection=“Horizontal” 横向排列, Vertical 纵向排列RepeatColumns=“3” 一行排3个RepeatLayout="UnorderedList 无序RepeatLayout="OrderedList 有序RepeatLayout=“Flow” 流式布局, 编译后的是 span