WebForm 控件

简单控件文本类: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
一、将数据放进去

<asp:DropDownList ID=“DropDownList1” runat=“server”>
</asp:DropDownList> <asp:Button ID=“Button1” runat=“server” Text=“按钮1” />
<asp:Label ID=“Label1” runat=“server” Text=“Label”></asp:Label>using System;
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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值