数据绑定

 

绑定到属性(字段)

绑定语法:<%#字段名或属性名%>

<body style=‘<%#bodystyle%>’>…</body>

protected string bodystyle;

protected void Page_Load(object sender, EventArgs e)

{

     bodystyle = "background-color:#ff0000";

}

数据绑定

protected void Page_Load(object sender, EventArgs e)

    {

        string str = "server=PC2011083011PDI\\SQLEXPRESS;database=province;integrated security=sspi";

        DataSet ds = new DataSet();

        using (SqlConnection sqlCnn=new SqlConnection())

        {

            sqlCnn.ConnectionString = str;

            SqlCommand sqlcmm = sqlCnn.CreateCommand();

            sqlcmm.CommandText = "select id,name from province";

            SqlDataAdapter da = new SqlDataAdapter(sqlcmm);

            da.Fill(ds);

        }

        this.DropDownList1.DataSource=ds.Tables[0];

        this.DropDownList1.DataTextField = "name";

        this.DropDownList1.DataValueField = "id";

        //this.DropDownList1.DataBind();

        this.RadioButtonList1.DataSource = ds.Tables[0];

        this.RadioButtonList1.DataTextField = "name";

        this.RadioButtonList1.DataValueField = "id";

        //this.RadioButtonList1.DataBind();

 

        this.CheckBoxList1.DataSource = ds.Tables[0];

        this.CheckBoxList1.DataTextField = "name";

        this.CheckBoxList1.DataValueField = "id";

 

        this.GridView1.DataSource = ds.Tables[0];

 

        this.DataBind();

}

使用DropDownList控件绑定

使用DataSource属性指定集合数据源,使用DataBind方法进行绑定。

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值