WebForm网页的数据架构及其连接技术PPT(31张)
- 格式:ppt
- 大小:653.00 KB
- 文档页数:31
WebForm控件(⼀)、连接数据库⼀、控件【简单控件】(⼀)⽂字显⽰1、Label →在html中相当于span <asp:Label ID="控件名 runat="server" Text="显⽰的⽂本"></asp:Label>2、Literal →仅⽂字→⼀般⽤来输出JS代码 <asp:Literal ID="Literal1" runat="server"></asp:Literal>(⼆)⽂字输⼊TextBox → TextMode不同效果不同<asp:TextBox ID="textbox1" runat="server" Enabled="True"></asp:TextBox> TextMode :默认是Text 单⾏⽂本输⼊框singleLine(<input name="txtuid" type="text" id="txtuid" disabled="disabled" /> ) 密码输⼊password(<input name="txtpwd" type="password" id="txtpwd" />) 多⾏⽂本输⼊motiline(<textarea name="txtmemo" rows="2" cols="20" id="txtmemo"></textarea> ) Warp:⾃动换⾏ Enabled:是否启⽤相当于html中的disabled是否可见 ReadOnly:只读 Text:相当于value(三)按钮1、Button →默认是html中的Submit(提交按钮)⽆普通按钮和刷新按钮,可以直接⽤input写 <asp:Button ID="Button1" runat="server" Text="注册" OnClick="Button1_Click" OnClientClick="confirm('really?')" /><input type="submit" name="Button1" value="注册" id="Button1" /> OnClientClick:在客户端点击时执⾏服务器上的代码,字符串属性,⾥⾯写JS代码 例:confirm:confirm('真的要删除吗?')默认确定或取消都会刷新页⾯,可以⽤if语句控制 text:html中的value2、ImageButton →图⽚按钮 html中type=image ImageUrl:图⽚地址3、LinkButton →超链接样式的按钮,仅仅是拥有超链接的样式,并⽆链接控件的相同属性:※边框三项:1、BorderColor:边框颜⾊ 2、BorderWidth:边框粗细 NotSet:不设置 None:⽆ Dotted:实⼼不连接⽅块 Dashed:四⾓ Solid:实线 Double:双实线 Groove:下凹效果 Ridge:上凸效果 Inset:效果同groove Outset:效果同ridge ※Height:⾼ Width:宽【复合控件】DropDownList → select option(html)<asp:DropDownList ID="DropDownList1" runat="server"></asp:DropDownList>显⽰数据:(写在load⾥⾯)⽅法1:DataSourceDropDownList1.DataSource = new NationData().Select();//数据源指向DropDownList1.DataTextField = "NationName";//显⽰字段绑定DropDownList1.DataValueField = "NationCode";//隐藏字段绑定DropDownList1.DataBind();⽅法2:Foreachif (!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;}DropDownList1.Items.Add(li);}}取数据:1、读取⼀条数据取出value值或 text值 DropDownList只能取⼀条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 → select option(html)<asp:ListBox ID="ListBox1" runat="server" SelectionMode="Multiple"></asp:ListBox>⽤法同DropDownList但是可以多选 - SelectionModeCheckBoxList<asp:CheckBoxList ID="CheckBoxList1" runat="server" RepeatLayout="UnorderedList"></asp:CheckBoxList>⽤法同DropDownListRepeatColumns:⼀⾏最多显⽰多少个数据RepeatDirection:Vetical垂直显⽰ Horizontal⽔平显⽰RepeatLayout:Table →⽤table布局 Flow →⽤span布局 UnorderedList →⽆序列表 OrderedList →有序列表RadioButtonList<asp:RadioButtonList ID="RadioButtonList1" runat="server"></asp:RadioButtonList>⽤法同DropDownListRepeatColumns:⼀⾏最多显⽰多少个数据RepeatDirection:Vetical垂直显⽰ Horizontal⽔平显⽰RepeatLayout:Table →⽤table布局 Flow →⽤span布局 UnorderedList →⽆序列表 OrderedList →有序列表http协议⽆状态性:每⼀次事件提交,都会将页⾯刷新,刷新就必⾛Load事件,重复绑定的情况判断页⾯是第⼀次加载,还是由已经加载出来的页⾯中的某个按钮执⾏了提交返回回来的if (!IsPostBack)load事件中95%的代码都要写在这⾥⾯代码委托添加点击事件:Button1.Click += Button1_Click;控件中的 name⽤于服务端 id⽤于客户端(js css)使⽤⼆、WebForm的数据库连接⽅式※放在App_Code⽂件夹下※web没有命名空间数据库连接同winform:1.实⼒类2.数据连接类和数据访问类写⼀块public class UsersData{SqlConnection conn = null;SqlCommand cmd = null;public UsersData(){conn = new SqlConnection("server=.;database=Data0617;user=sa;pwd=123");cmd = conn.CreateCommand();}///<summary>///⽤户验证///</summary>///<param name="Uname">验证的⽤户名</param>///<param name="Pwd">验证的密码</param>///<returns></returns>public bool Select(string Uname, string Pwd){bool has = false;mandText = "select *from Users where UserName =@a and PassWord=@b"; cmd.Parameters.Clear();cmd.Parameters.Add("@a", Uname);cmd.Parameters.Add("@b", Pwd);conn.Open();SqlDataReader dr = cmd.ExecuteReader();if (dr.HasRows){has = true;}conn.Close();return has;}}。