时间:2016-02-15 21:45 来源: 我爱IT技术网 作者:佚名
欢迎您访问我爱IT技术网,今天小编为你分享的编程技术是:【asp.net 数据绑定的实例代码】,下面是详细的讲解!
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();
}
}
}//实现省市二级联动
}
关于asp.net 数据绑定的实例代码的用户互动如下:
相关问题:
答: >>详细
相关问题:
答: >>详细
相关问题:
答: >>详细
- 【创建】ASP.NET Web API教程 创建域模型的方法详
- 【页面打印】关于ASP.NET页面打印技术的常用方法
- 【服务器】asp.net页面状态管理cookie和服务器状
- 如何取消.net后台线程的执行
- 【WeakReference】WeakReference(弱引用)让GC需要
- 【ajax格式】asp.net中在用ajax格式传递数据到asp
- 【字符文本】asp.net 数据绑定 使用eval 时候报
- 【Repeater控件】.NET实现Repeater控件+AspNetPag
- 【客户端】获取客户端IP地址c#/vb.net各自实现代
- 【asp】asp.net上传execl文件后 在页面上加载显示
- 评论列表(网友评论仅供网友表达个人看法,并不表明本站同意其观点或证实其描述)
-
