9月7日学习记录

checkboxlist的用法  :直接根据数据库中表的字段来设置多选菜单。

//创建连接数据库的静态类
        //静态类不需要新建对象
        string sql = "server=.;database=list;integrated Security=SSPI;";
        SqlConnection con = new SqlConnection(sql);
        return con;

  //绑定
        string sql = "select * from personLike";
        SqlConnection con = DB.createConnection();
        con.Open();
        SqlCommand cmd = new SqlCommand(sql,con);
        SqlDataReader dr = cmd.ExecuteReader();
        this.CheckBoxList1.DataSource = dr;
        this.CheckBoxList1.DataTextField = "likeContent";
        this.CheckBoxList1.DataValueField = "id";
        this.CheckBoxList1.DataBind();
        dr.Close();
        con.Close();

 

 protected void Button1_Click(object sender, EventArgs e)
    {
        for (int i = 0; i < this.CheckBoxList1.Items.Count - 1; i++)
        {
            if(this.CheckBoxList1.Items[i].Selected)
            {
                //如果是获取选中项的主键值用value,获取文本值用text
                Response.Write(this.CheckBoxList1.Items[i].Value.ToString()+"-"+this.CheckBoxList1.Items[i].Text+"<br>");
            }
        }

radiobuttonlist的用法和checkboxlist的用法基本相同,前者是单选,后者可以多选。

Imagebutton用法:

protected void ImageButton1_Click(object sender, ImageClickEventArgs e)
    {
        //X和Y可以控制Imagebutton的坐标、
        if (e.X < 150)
        {
            Response.Write("Left");
        }
        else
        {
            Response.Write("right");
        }

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值