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);
t
相关新闻>>
- 发表评论
-
- 最新评论 进入详细评论页>>
今日头条
更多>>您可能感兴趣的文章
- asp.net js模拟Button点击事件
- 谈.Net委托与线程——创建无阻塞的异步调用(一
- 微软ASP.NET站点部署指南(11):部署SQL Server数据
- ASP.NET数据格式的Format--DataFormatString
- 教你如何来恢复一个丢失的数据文件
- winform下通过webclient使用非流方式上传(post)数据和
- MVC中一个表单实现多个提交按钮(一个action搞定
- Asp.net MVC源码分析--Model Validation(Client端)实现(2)
- asp.net 六大内置对象(2)
- Pro ASP.NET MVC 3 Framework学习笔记之九