一、控件

【简单控件】

(一)文字显示

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. JAVA语法题

    import java.util.*; public class Birthdays { public static void main(String[] args){ Map<Friends, ...

  2. Android开发:组播(多播)与广播

    近期由于需要编写能够使同一局域网中的Android客户端与PC端进行自动匹配通信功能的程序,学习并试验了JAVA组播与广播的内容,记录一些理解如下: 一.组播(多播) 背景知识:组播使用UDP对一定范 ...

  3. STM32之FreeRTOS

    STM32之FreeRTOS http://www.freertos.org/index.html http://www.freertos.org/a00090.html#ST http://www. ...

  4. With PHP frameworks, why is the “route” concept used?

    http://programmers.stackexchange.com/questions/122190/with-php-frameworks-why-is-the-route-concept-u ...

  5. iOS学习笔记(十三)——获取手机信息(UIDevice、NSBundle、NSLocale)

    iOS的APP的应用开发的过程中,有时为了bug跟踪或者获取用反馈的需要自动收集用户设备.系统信息.应用信息等等,这些信息方便开发者诊断问题,当然这些信息是用户的非隐私信息,是通过开发api可以获取到 ...

  6. 解决eclipse报PermGen space异常的问题

    开发中遇到Eclipse报错:java.lang.OutOfMemoryError: PermGen space. 网搜到三种解决方法,最终还是第三种方法起了作用.记录日志,备用. 原文地址: htt ...

  7. js盒子模型

    1.js盒子模型 指的是通过js中提供的一系列的属性和方法,获取页面中元素的样式信息值 例: #box有很多自己的私有属性: HTMLDivElement.prototype->HTMLElem ...

  8. iOS 之 设置横竖屏及ViewWillAppear及视图与导航控制器嵌套时的不同反应

    设置横竖屏不成功,可能跟所在导航控制器有关 视图没有导航控制器时,又有可能不调用ViewWillAppear,这是我遇到的问题.

  9. Unicode范围

    unicode编码范围: 汉字:[0x4e00,0x9fa5](或十进制[19968,40869]) 数字:[0x30,0x39](或十进制[48, 57]) 小写字母:[0x61,0x7a](或十进 ...

  10. 【转载】doxygen+graphviz生成代码文档

    一.工具 doxygen:http://www.stack.nl/~dimitri/doxygen/download.html graphviz:http://www.graphviz.org/ 二. ...