一、控件

【简单控件】

(一)文字显示

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中的value

2、ImageButton → 图片按钮 html中type=image
             ImageUrl:图片地址

3、LinkButton → 超链接样式的按钮,仅仅是拥有超链接的样式,并无链接

控件的相同属性:
※边框三项:1、BorderColor:边框颜色

         2、BorderWidth:边框粗细        

         3、BorderStyle:边框样式

                 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:DataSource

        DropDownList1.DataSource = new NationData().Select();//数据源指向
DropDownList1.DataTextField = "NationName";//显示字段绑定
DropDownList1.DataValueField = "NationCode";//隐藏字段绑定
DropDownList1.DataBind();

方法2:Foreach

        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;
}
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

但是可以多选 - SelectionMode

CheckBoxList

<asp:CheckBoxList ID="CheckBoxList1" runat="server" RepeatLayout="UnorderedList"></asp:CheckBoxList>

用法同DropDownList

RepeatColumns:一行最多显示多少个数据

RepeatDirection:Vetical垂直显示  Horizontal水平显示

RepeatLayout:Table → 用table布局

         Flow → 用span布局

         UnorderedList → 无序列表

         OrderedList → 有序列表

RadioButtonList

<asp:RadioButtonList ID="RadioButtonList1" runat="server"></asp:RadioButtonList>

用法同DropDownList

RepeatColumns:一行最多显示多少个数据

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;
cmd.CommandText = "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;
}
}

WebForm 控件(一)、连接数据库的更多相关文章

  1. 将开始我的WebForm控件开发之旅

    时间总是过得很快,一转眼三个月就过去了,三个月内发生了很多的事.因为学校的学习,离开了我入门WPF的公司:开发了第一个外包项目,做的是WebForm的:而且了马上要毕业了,毕业后的公司应该是专门用We ...

  2. WebForm控件多字段绑定

    一.这里的多字段绑定是什么意思? 多字段绑定控件其实就是把两个字段显示在一起作为一个字段现在控件上! 可能读者看了可能还是有点懵逼,说的还是比较抽象!的确,光从这上面的确是无法具体到某特定一种情况!那 ...

  3. webform控件

    简单控件: 1.Label 会被编译成span标签 属性: Text:文本内容 CssClass:CSS样式 <asp:Label ID=" CssClass="aaa&qu ...

  4. WebForm控件--2016年12月29日

    简单控件 1.Label  =>   <span id="Label1">Label1</span> 2.Literal  =>  Text 填 ...

  5. 常用的WebForm 控件

    首先回忆一下Html页中的12个表单元素 .文本类 文本框 <input type="text" id="" name="" valu ...

  6. WebForm控件Repeater

    我们会发现用拼接字符串来显示一个查询非常的麻烦,有一个控件Repeater帮助你,省去写Foreach LinQ to SQL类 函数类: using System; using System.Col ...

  7. WebForm 控件

    一.简单控件 1.Label(作用:显示文字) Web中: <asp:Label ID="Label1" runat="server" Text=&quo ...

  8. WebForm 控件(二)

    控件 Calendar:日历控件 但是html代码量太大不适用 FileUpdate: 文件上传 HiddenField:隐藏域 Image: 图片  可以直接给URL 不适用可用html代码写 Ta ...

  9. 关于获取WebForm控件的问题

    遇到这样的一个问题: 在GridView加载了数据之后,GridView的个别列被设置为TextBox单元格,就是可以修改数量了,单价什么的: 这样就触发了TextChanged事件: 现在要记录谁修 ...

随机推荐

  1. Apriori算法第一篇

    摘要: Apriori算法是产生k项高频项目组的一般手段.算法概要:首先产生k项高频项目集合Lk,自身链接形成k+1项的项目结合C(k+1),然后剪枝(去掉以前去掉的不满足支持度的高频),生成K=1项 ...

  2. (简单) POJ 1195 Mobile phones,二维树状数组。

    Description Suppose that the fourth generation mobile phone base stations in the Tampere area operat ...

  3. 关于LCD以及BMP和RGB565

    源: 关于LCD以及BMP和RGB565

  4. NYoj1058

    水题,dfs,裸的,本来这道题没什么好写的,只是第一次写的代码慢的出奇,纪念一下那个奇怪的思路 链接:http://acm.nyist.net/JudgeOnline/problem.php?pid= ...

  5. html 设置页脚div一直在页面底部

    先上代码 <!DOCTYPE HTML> <html lang="en" style="height: 100%; width: 100%;" ...

  6. PageRank——Google的民主表决算法

    1.搜索和民主表决:      当大多数人认为一件事为真的时候,那么这件事就是为真:即搜索时,其他网页对认为此网页好时,那么此网页排名应该靠前   2.PageRank思想:      i.起源:   ...

  7. github上forck一个分支之后,如何和主分支同步

    github forck一个分之后,如果过一段时间就会和主分支的差异比较大. 这样提交pr的时候 就会冲突,这个时候我们就需要和主分支同步代码 git remote add upstream git@ ...

  8. Struts2的那些小细节

    1.result中传多个参数,&不允许使用需要转义&即多个参数之间用&隔开 <result type="redirectAction">show ...

  9. 【腾讯Bugly干货分享】你为什么需要 Kotlin

    本文来自于腾讯Bugly公众号(weixinBugly),未经作者同意,请勿转载,原文地址:http://mp.weixin.qq.com/s/xAFKGarHhfQ3nKUwPDlWwQ 一.往事 ...

  10. dubbo框架揭秘之服务发布

    通常情况下是通过Spring配置的方式去实现服务的发布,为了方便调试,我就不采用Spring配置的方式. DemoService demo = new DemoServiceImpl(); Appli ...