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)文章
.NET Core中HttpClient的正確打開(kāi)方式
這篇文章主要給大家介紹了關(guān)于.NET Core中HttpClient的正確打開(kāi)方式,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2019-01-01
asp.net 長(zhǎng)文章通過(guò)設(shè)定的行數(shù)分頁(yè)
長(zhǎng)文章通過(guò)設(shè)定的行數(shù)來(lái)實(shí)現(xiàn)分頁(yè)的代碼。2009-12-12
Visual Studio 2015和 .NET Core安裝教程
這篇文章主要為大家詳細(xì)介紹了Visual Studio Community 2015和 .NET Core安裝圖文教程,感興趣的小伙伴們可以參考一下2016-07-07
.Net 對(duì)于PDF生成以及各種轉(zhuǎn)換的操作
這篇文章主要介紹了.Net 對(duì)于PDF生成以及各種轉(zhuǎn)換的操作,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2020-06-06
javascript判斷是否有對(duì)RadioButtonList選項(xiàng)選擇
寫(xiě)個(gè)Javascript來(lái)判斷是否有對(duì)RadioButtonList選項(xiàng)選擇,附動(dòng)畫(huà)演示,感興趣的朋友可以了解下,希望對(duì)您們有幫助2013-01-01
asp.net實(shí)現(xiàn)非常實(shí)用的自定義頁(yè)面基類(lèi)(附源碼)
這篇文章主要介紹了asp.net實(shí)現(xiàn)非常實(shí)用的自定義頁(yè)面基類(lèi),包含日志處理、控件賦值、異常處理等功能,非常具有實(shí)用價(jià)值,需要的朋友可以參考下2015-11-11
使用ASP.NET一般處理程序或WebService返回JSON的實(shí)現(xiàn)代碼
今天, 將為大家說(shuō)明如何在 ASP.NET 中使用一般處理程序或者 WebService 向 javascript 返回 JSON2011-10-10

