发布于 2016-06-11 11:07:29 | 101 次阅读 | 评论: 0 | 来源: 网友投递

这里有新鲜出炉的精品教程,程序狗速度看过来!

ASP.NET

ASP.NET 是.NET FrameWork的一部分,是一项微软公司的技术,是一种使嵌入网页中的脚本可由因特网服务器执行的服务器端脚本技术,它可以在通过HTTP请求文档时再在Web服务器上动态创建它们。 指 Active Server Pages(动态服务器页面) ,运行于 IIS(Internet Information Server 服务,是Windows开发的Web服务器)之中的程序 。


这篇文章介绍了asp.net 数据绑定的实例代码,有需要的朋友可以参考一下

public partial class _Default : System.Web.UI.Page
{
    protected string title="大家好";            //前台代码<title><%#title %></title>
    protected void Page_Load(object sender, EventArgs e)
    {
        DataSet ds = new DataSet();
        string sql = ConfigurationManager.ConnectionStrings["strsql"].ConnectionString;
        using (SqlConnection sqlCnn=new SqlConnection(sql))
        {
            using (SqlCommand sqlCmm=sqlCnn.CreateCommand())
            {
                sqlCmm.CommandText = "select * from List";
                SqlDataAdapter adapter = new SqlDataAdapter(sqlCmm);
                adapter.Fill(ds);
            }
            this.RadioButtonList1.DataSource = ds.Tables[0];
            this.RadioButtonList1.DataTextField = "listname";
            this.RadioButtonList1.DataValueField = "id";
            //this.RadioButtonList1.DataBind();
            this.CheckBoxList1.DataSource = ds.Tables[0];
            this.CheckBoxList1.DataTextField = "listname";
            this.CheckBoxList1.DataValueField = "id";
            //this.RadioButtonList1.DataBind();
            this.DataBind();
        }            //数据绑定到RadioButtonList,CheckBoxList
        if (!IsPostBack)
        {
            DataSet ds1 = new DataSet();
            using (SqlConnection sqlCnn1 = new SqlConnection(sql))
            {
                using (SqlCommand sqlCmm1 = sqlCnn1.CreateCommand())
                {
                    sqlCmm1.CommandText = "select provinceid,provincename from Province";
                    SqlDataAdapter adapter = new SqlDataAdapter(sqlCmm1);
                    adapter.Fill(ds1);
                    this.DropDownList1.DataSource = ds1.Tables[0];
                    this.DropDownList1.DataTextField = "provincename";
                    this.DropDownList1.DataValueField = "provinceid";
                    this.DropDownList1.DataBind();
                }
            }
        }
    }
    protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
    {
        DataSet ds = new DataSet();
        string str = ConfigurationManager.ConnectionStrings["strsql"].ConnectionString;
        using (SqlConnection sqlCnn = new SqlConnection(str))
        {
            using (SqlCommand sqlCmm = sqlCnn.CreateCommand())
            {
                sqlCmm.CommandText = "select cityid,cityname from City where provinceid='" + this.DropDownList1.SelectedValue + "'";
                SqlDataAdapter adapter = new SqlDataAdapter(sqlCmm);
                adapter.Fill(ds);
                this.DropDownList2.DataSource = ds.Tables[0];
                this.DropDownList2.DataTextField = "cityname";
                this.DropDownList2.DataValueField = "cityid";
                this.DropDownList2.DataBind();
            }
        }
    }//实现省市二级联动
}


最新网友评论  共有(0)条评论 发布评论 返回顶部

Copyright © 2007-2017 PHPERZ.COM All Rights Reserved   冀ICP备14009818号  版权声明  广告服务