簡單資料繫結和複雜資料繫結
using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using System.Data; using System.Data.SqlClient; using System.Configuration; public partial class Default2 : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { } protected void Button1_Click(object sender, EventArgs e) { string strcon = ConfigurationManager.ConnectionStrings["con"].ConnectionString; // string con = "server=.\\sqlexpress;initial catalog=english;integrated security=true"; using (SqlConnection con1 = new SqlConnection(strcon)) { DataSet dt = new DataSet(); using (SqlCommand cmd = new SqlCommand("select * from [user]", con1)) { con1.Open(); SqlDataAdapter ada = new SqlDataAdapter(cmd); ada.Fill(dt); DropDownList1.DataSource = dt.Tables[0]; DropDownList1.DataTextField = "name"; DropDownList1.DataTextField = "id"; DropDownList1.DataBind(); RadioButtonList1.DataSource = dt.Tables[0]; RadioButtonList1.DataTextField = "stuid"; RadioButtonList1.DataValueField = "id"; RadioButtonList1.DataBind(); CheckBoxList1.DataSource = dt.Tables[0]; CheckBoxList1.DataTextField = "name"; CheckBoxList1.DataBind(); } } } //資料集 protected void Button2_Click(object sender, EventArgs e) { string strcon = ConfigurationManager.ConnectionStrings["con"].ConnectionString; DataTable dt = new DataTable(); using (SqlConnection con=new SqlConnection(strcon)) { using (SqlCommand cmd=new SqlCommand("select * from [user]",con)) { con.Open(); using (SqlDataReader myreader=cmd.ExecuteReader()) { dt.Load(myreader); } } } GridView gv = new GridView(); gv.DataSource = dt; gv.ID = "baining"; gv.DataBind(); disp.Controls.Add(gv); } //用DataTable protected void Button3_Click(object sender, EventArgs e) { Class1.prove.getname(); DropDownList1.DataSource = DropDownList1.DataSource = "id"; } }
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
public partial class Default2 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
string strcon = ConfigurationManager.ConnectionStrings["con"].ConnectionString;
// string con = "server=.\\sqlexpress;initial catalog=english;integrated security=true";
using (SqlConnection con1 = new SqlConnection(strcon))
{
DataSet dt = new DataSet();
using (SqlCommand cmd = new SqlCommand("select * from [user]", con1))
{
con1.Open();
SqlDataAdapter ada = new SqlDataAdapter(cmd);
ada.Fill(dt);
DropDownList1.DataSource = dt.Tables[0];
DropDownList1.DataTextField = "name";
DropDownList1.DataTextField = "id";
DropDownList1.DataBind();
RadioButtonList1.DataSource = dt.Tables[0];
RadioButtonList1.DataTextField = "stuid";
RadioButtonList1.DataValueField = "id";
RadioButtonList1.DataBind();
CheckBoxList1.DataSource = dt.Tables[0];
CheckBoxList1.DataTextField = "name";
CheckBoxList1.DataBind();
}
}
} //資料集
protected void Button2_Click(object sender, EventArgs e)
{
string strcon = ConfigurationManager.ConnectionStrings["con"].ConnectionString;
DataTable dt = new DataTable();
using (SqlConnection con=new SqlConnection(strcon))
{
using (SqlCommand cmd=new SqlCommand("select * from [user]",con))
{
con.Open();
using (SqlDataReader myreader=cmd.ExecuteReader())
{
dt.Load(myreader);
}
}
}
GridView gv = new GridView();
gv.DataSource = dt;
gv.ID = "baining";
gv.DataBind();
disp.Controls.Add(gv);
} //用DataTable
protected void Button3_Click(object sender, EventArgs e)
{
Class1.prove.getname();
DropDownList1.DataSource =
DropDownList1.DataSource = "id";
}
}
相關文章
- vue select 繫結複雜資料和預設顯示Vue
- Vue資料繫結簡析Vue
- 資料繫結
- 資料繫結原理
- 簡單易懂的雙向資料繫結解讀
- JavaScript實現簡單的雙向資料繫結JavaScript
- 第二講、Vue3.x繫結資料、繫結html、繫結屬性、迴圈資料VueHTML
- angular 多選表單資料繫結Angular
- Vue的資料繫結Vue
- 資料繫結之謎
- 【Angular-資料繫結】Angular
- 2、理解資料繫結
- 手動簡單實現Vue雙向資料繫結Vue
- 簡單易懂的Vue資料繫結原始碼解讀Vue原始碼
- 動態繫結和靜態繫結的簡單理解
- class 和 style 資料動態繫結
- 模板語法之--強制資料繫結和繫結事件監聽事件
- 從單向到雙向資料繫結
- 【阿不】深入ASP.NET資料繫結(中)—資料雙向繫結機理ASP.NET
- 關於簡單的資料雙向繫結原理,defineProperty 和Proxy演示
- vue資料繫結原始碼Vue原始碼
- Binding(一):資料繫結
- JS雙向資料繫結JS
- SpringMVC資料繫結demoSpringMVC
- Flex 資料繫結備忘Flex
- javascript實現資料的雙向繫結(手動繫結)JavaScript
- [系列] Gin框架 - 資料繫結和驗證框架
- SAP UI5 初學者教程之十九 - SAP UI5 資料型別和複雜的資料繫結UI資料型別
- angular1資料繫結例子Angular
- Vue資料雙向繫結原理Vue
- vue雙向資料繫結原理Vue
- Winform控制元件繫結資料ORM控制元件
- Study Blazor .NET(四)資料繫結Blazor
- 原生js雙向資料繫結JS
- XAML資料繫結(Data Binding)
- Vue.js資料繫結原理Vue.js
- [JS] 資料雙向繫結原理JS
- angularjs中的資料繫結AngularJS