WebSite9

DataListBingding.aspx.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
public partial class DataListBingding : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack) listbind();

    }
    void listbind() {
        string sqlconnstr = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
        DataSet ds = new DataSet();
        SqlConnection sqlconn = new SqlConnection(sqlconnstr);
        SqlDataAdapter sqld = new SqlDataAdapter("select * from student", sqlconn);
        sqld.Fill(ds, "tabstudent");
     
        DataList1.DataBind();

    }
}

SingleValueBinding.aspx.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class SingleValueBinding : System.Web.UI.Page
{
    public String SingleValueBindingStr = "单值绑定";
    public String SingleValueBindingStr1 = "男";
    protected void Page_Load(object sender, EventArgs e)
    {
        Page.DataBind();
        this.TextBox1.Text = this.SingleValueBindingStr + "2";
        this.TextBox2.Text = this.SingleValueBindingStr + "3";
        this.TextBox3.Text = this.SingleValueBindingStr1;
    }
}

ListValueBinding.aspx.cs

public partial class ListValueBinding : System.Web.UI.Page
{
   
    //定义并初始化字符串数组
    String[] DataSourceForDDL = new String[] { "张小兵", "李明", "陈飞" };
    //定义哈希表
    Hashtable DataSourceForCBL = new Hashtable(3);
    //定义Arraylist
    ArrayList DataSourceForBL = new ArrayList();
    protected void Page_Load(object sender, EventArgs e)
    {
       
        if (!IsPostBack) {
            //初始化哈希表DataSourceForCBL
            this.DataSourceForCBL.Add("徐明明", "男");
            this.DataSourceForCBL.Add("韩旭", "女");
            this.DataSourceForCBL.Add("陈静", "女");
            //初始化DataSourceForBL
            this.DataSourceForBL.Add(new Key_ValueClass("百度", "http://www.baidu.com"));
            this.DataSourceForBL.Add(new Key_ValueClass("CSDN", "http://www.csdn.net"));
            //为dropdownlist绑定数据
            this.DropDownList1.DataSource = this.DataSourceForDDL;
            this.DropDownList1.DataBind();
            //完成绑定后在dropdownlist中第一个位置插入一个数据项
            this.DropDownList1.Items.Insert(0, "请选择");
            //为checkboxlist绑定数据
            this.CheckBoxList1.DataSource = this.DataSourceForCBL;
            //由于哈希表中存储一个键值对的集合并希望在checkboxlist中处理键值对,因此设定数据源后还需
            //设定datatextlist和datavaluefield属性
            this.CheckBoxList1.DataTextField = "key";
            this.CheckBoxList1.DataValueField = "value";
            this.CheckBoxList1.DataBind();
            this.BulletedList1.DataSource = this.DataSourceForBL;
            this.BulletedList1.DataTextField = "Name";
            this.BulletedList1.DataValueField = "Url";
            this.BulletedList1.DataBind();

        }

    }

    protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
    {
        TextBox2.Text = "";
        TextBox2.Text = DropDownList1.SelectedValue;
    }

    protected void Button1_Click(object sender, EventArgs e)
    {
        TextBox1.Text = "";
        foreach (ListItem li in CheckBoxList1.Items)
        {
            if (li.Selected) TextBox1.Text += li.Text + ":" + li.Value + ",";
        }
    }
}

dropdownlist3.aspx.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
public partial class dropdownlist3 : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        string sqlconnstr = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;


    }
}

GridViewBingding.aspx.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;

public partial class GridViewBingding : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        string sqlconnstr = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
        DataSet ds = new DataSet();
        using (SqlConnection sqlconn = new SqlConnection(sqlconnstr))
        {
            SqlDataAdapter sqld = new SqlDataAdapter("select * from student", sqlconn);
            sqld.Fill(ds, "tabstudent");
        }
        GridView1.DataSource = ds.Tables["tabstudent"].DefaultView;
        GridView1.DataBind();
        Label1.Text = "查找成功";

    }

    protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
    {

    }
}

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值