时间:2021-05-28
复制代码 代码如下:
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();
}
}
}//实现省市二级联动
}
声明:本页内容来源网络,仅供用户参考;我单位不保证亦不表示资料全面及准确无误,也不保证亦不表示这些资料为最新信息,如因任何原因,本网内容或者用户因倚赖本网内容造成任何损失或损害,我单位将不会负任何法律责任。如涉及版权问题,请提交至online#300.cn邮箱联系删除。
本文实例讲述了ASP.NET中repeater控件用法。分享给大家供大家参考。具体实现方法如下:repeater绑定数据:复制代码代码如下:protectedv
asp.net操作access数据库是常见的数据库操作应用,本文就来实例讲解一下asp.net实现access数据库分页的方法。希望对大家的asp.net程序设
本文实例讲述了asp.net实现XML文件读取数据绑定到DropDownList的方法。分享给大家供大家参考,具体如下:1、绑定DropDownList:ddl
本文实例讲述了asp.net实现Gradview绑定数据库数据并导出Excel的方法。分享给大家供大家参考,具体如下:protectedvoidshowData
用惯了WPF的绑定,ASP.NET的绑定貌似不是很好用。下面看看ASP.NET绑定的用法。一般来说可以直接绑定DataTable的,不过我觉得绑定List比较符