一、控件

【简单控件】

(一)文字显示

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. deb安装了些啥?

    http://www.cyberciti.biz/faq/view-contents-of-deb-file/

  2. HTML5绘制矩形和圆形并且还有获取在这个图层内的坐标的思路和代码 - feilong_12的专栏 - 博客频道 - CSDN.NET

    body{ font-family: "Microsoft YaHei UI","Microsoft YaHei",SimSun,"Segoe UI& ...

  3. (中等) POJ 2886 Who Gets the Most Candies? , 反素数+线段树。

    Description N children are sitting in a circle to play a game. The children are numbered from 1 to N ...

  4. 起步X5 的铛铛的安装部署过程

    (2017年1月)主要资料: 1.铛铛的IM Server即时通信服务使用 actor   https://github.com/actorapp/actor-platform ,开发者网站是:htt ...

  5. ADXL345加速度传感器驱动

    ADXL345 是 ADI 公司的一款 3 轴.数字输出的加速度传感器.ADXL345 是 ADI 公司推 出的基于 iMEMS 技术的 3 轴.数字输出加速度传感器.该加速度传感器的特点有:    ...

  6. java学习(二)--excel导出

    public static String writeFile(String fileName, String[][] content) { WritableWorkbook wwb = null; S ...

  7. PHP利用数组构造JSON

    问题起因 以往都是直接用构造数组的形式构造json 例子: $arr = array("A"=>"1","B"=>"2 ...

  8. 数字(数学)操作类 Math Random 类 ,大数字操作类

    Math 提供了大量的数学操作方法 Math类中所有的方法都是static 方法

  9. Button背景图片有拉伸

    1.将图片做成9.png2.用TextView 3.将minHeight, minWidth设为0 4.http://blog.csdn.net/oathevil/article/details/23 ...

  10. bzoj2120: 数颜色 &&bzoj2453: 维护队列

    题目大意: 你小时候玩过弹珠吗? 小朋友A有一些弹珠,A喜欢把它们排成队列,从左到右编号为1到N.为了整个队列鲜艳美观,小朋友想知道某一段连续弹珠中,不同颜色的弹珠有多少.当然,A有时候会依据个人喜好 ...