asp.net

位置:IT落伍者 >> asp.net >> 浏览文章

asp.net 数据绑定的实例代码


发布日期:2019年11月13日
 
asp.net 数据绑定的实例代码
这篇文章介绍了aspnet 数据绑定的实例代码有需要的朋友可以参考一下复制代码 代码如下:


public partial class _Default : SystemWebUIPage
{
protected string title="大家好"; //前台代码<title><%#title %></title>
protected void Page_Load(object sender EventArgs e)
{
DataSet ds = new DataSet();
string sql = ConfigurationManagerConnectionStrings["strsql"]ConnectionString;
using (SqlConnection sqlCnn=new SqlConnection(sql))
{
using (SqlCommand sqlCmm=sqlCnnCreateCommand())
{
sqlCmmCommandText = "select * from List";
SqlDataAdapter adapter = new SqlDataAdapter(sqlCmm);
adapterFill(ds);
}
thisRadioButtonListDataSource = dsTables[];
thisRadioButtonListDataTextField = "listname";
thisRadioButtonListDataValueField = "id";
//thisRadioButtonListDataBind();
thisCheckBoxListDataSource = dsTables[];
thisCheckBoxListDataTextField = "listname";
thisCheckBoxListDataValueField = "id";
//thisRadioButtonListDataBind();
thisDataBind();
} //数据绑定到RadioButtonListCheckBoxList
if (!IsPostBack)
{
DataSet ds = new DataSet();
using (SqlConnection sqlCnn = new SqlConnection(sql))
{
using (SqlCommand sqlCmm = sqlCnnCreateCommand())
{
sqlCmmCommandText = "select provinceidprovincename from Province";
SqlDataAdapter adapter = new SqlDataAdapter(sqlCmm);
adapterFill(ds);
thisDropDownListDataSource = dsTables[];
thisDropDownListDataTextField = "provincename";
thisDropDownListDataValueField = "provinceid";
thisDropDownListDataBind();
}
}
}
}
protected void DropDownList_SelectedIndexChanged(object sender EventArgs e)
{
DataSet ds = new DataSet();
string str = ConfigurationManagerConnectionStrings["strsql"]ConnectionString;
using (SqlConnection sqlCnn = new SqlConnection(str))
{
using (SqlCommand sqlCmm = sqlCnnCreateCommand())
{
  sqlCmmCommandText = "select cityidcityname from City where  provinceid=" + thisDropDownListSelectedValue + "";
SqlDataAdapter adapter = new SqlDataAdapter(sqlCmm);
adapterFill(ds);
thisDropDownListDataSource = dsTables[];
thisDropDownListDataTextField = "cityname";
thisDropDownListDataValueField = "cityid";
thisDropDownListDataBind();
}
}
}//实现省市二级联动
}

               

上一篇:asp.net StreamReader 创建文件的实例代码

下一篇:ASP.NET编程的十大技巧