亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

asp.net 數(shù)據(jù)綁定的實(shí)例代碼

 更新時(shí)間:2013年07月30日 10:46:06   作者:  
這篇文章介紹了asp.net 數(shù)據(jù)綁定的實(shí)例代碼,有需要的朋友可以參考一下
復(fù)制代碼 代碼如下:

public partial class _Default : System.Web.UI.Page
{
    protected string title="大家好";            //前臺(tái)代碼<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();
        }            //數(shù)據(jù)綁定到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();
            }
        }
    }//實(shí)現(xiàn)省市二級(jí)聯(lián)動(dòng)
}

相關(guān)文章

  • Asp.net后臺(tái)把腳本樣式輸出到head標(biāo)簽中節(jié)省代碼冗余

    Asp.net后臺(tái)把腳本樣式輸出到head標(biāo)簽中節(jié)省代碼冗余

    最近在學(xué)習(xí)開(kāi)發(fā)服務(wù)器控件,其它就少不了為控件注冊(cè)js和css之類的資源文件,或者直接注冊(cè)純腳本樣式。其中就遇到如下問(wèn)題     1、 注冊(cè)的資源文件或純腳本樣式在生成的頁(yè)面中都不在head標(biāo)簽中(當(dāng)然這個(gè)不影響頁(yè)面功能)     2、 一個(gè)頁(yè)面使用多個(gè)一樣的控件時(shí),會(huì)出現(xiàn)重復(fù)輸入(出現(xiàn)多余代碼)
    2013-02-02
  • C#中OpenFileDialog和PictrueBox的用法分析

    C#中OpenFileDialog和PictrueBox的用法分析

    這篇文章主要介紹了C#中OpenFileDialog和PictrueBox的用法,以實(shí)例的形式較為詳細(xì)的分析了OpenFileDialog和PictrueBox使用時(shí)的注意事項(xiàng)與具體用法,具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2014-11-11
  • ASP.NET MVC Webuploader實(shí)現(xiàn)上傳功能

    ASP.NET MVC Webuploader實(shí)現(xiàn)上傳功能

    這篇文章主要為大家詳細(xì)介紹了ASP.NET MVC Webuploader實(shí)現(xiàn)上傳功能,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2018-09-09
  • asp.net頁(yè)面SqlCacheDependency緩存實(shí)例

    asp.net頁(yè)面SqlCacheDependency緩存實(shí)例

    這篇文章主要介紹了asp.net頁(yè)面SqlCacheDependency緩存實(shí)例,以一個(gè)完整實(shí)例來(lái)展現(xiàn)asp.net中緩存技術(shù)的使用方法,需要的朋友可以參考下
    2014-08-08
  • C#中Dictionary幾種遍歷的實(shí)現(xiàn)代碼

    C#中Dictionary幾種遍歷的實(shí)現(xiàn)代碼

    C#中Dictionary幾種遍歷的實(shí)現(xiàn)代碼,需要的朋友可以參考一下
    2013-02-02
  • ASP.NET?MVC前臺(tái)動(dòng)態(tài)添加文本框并在后臺(tái)使用FormCollection接收值

    ASP.NET?MVC前臺(tái)動(dòng)態(tài)添加文本框并在后臺(tái)使用FormCollection接收值

    這篇文章介紹了ASP.NET?MVC前臺(tái)動(dòng)態(tài)添加文本框并在后臺(tái)使用FormCollection接收的方法,文中通過(guò)示例代碼介紹的非常詳細(xì)。對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2022-08-08
  • .Net防sql注入的幾種方法

    .Net防sql注入的幾種方法

    這篇文章主要給大家總結(jié)介紹了關(guān)于.Net防sql注入的幾種方法,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家學(xué)習(xí)或者使用.Net具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面來(lái)一起學(xué)習(xí)學(xué)習(xí)吧
    2019-06-06
  • 合并兩個(gè)DataSet的數(shù)據(jù)內(nèi)容的方法

    合并兩個(gè)DataSet的數(shù)據(jù)內(nèi)容的方法

    合并兩個(gè)DataSet的數(shù)據(jù)內(nèi)容的方法,需要的朋友可以參考一下
    2013-03-03
  • ASP.NET MVC生成靜態(tài)頁(yè)面的方法

    ASP.NET MVC生成靜態(tài)頁(yè)面的方法

    對(duì)于網(wǎng)站來(lái)說(shuō),生成純html靜態(tài)頁(yè)面除了有利于seo外,還可以減輕網(wǎng)站的負(fù)載能力和提高網(wǎng)站性能。本篇文章主要介紹了ASP.NET MVC生成靜態(tài)頁(yè)面的方法,有興趣的可以了解一下。
    2017-03-03
  • Ajax.net 顯示錯(cuò)誤信息的設(shè)置

    Ajax.net 顯示錯(cuò)誤信息的設(shè)置

    有時(shí)候我們?cè)谑褂胊sp.net想讓他顯示出錯(cuò)的原因等情況,大家可以仔細(xì)看下參數(shù),屬性等
    2009-01-01

最新評(píng)論