簡單資料繫結和複雜資料繫結
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
- Angular | 理解資料繫結Angular
- Binding(一):資料繫結
- SpringMVC資料繫結demoSpringMVC
- 手動簡單實現Vue雙向資料繫結Vue
- 簡單易懂的Vue資料繫結原始碼解讀Vue原始碼
- 模板語法之--強制資料繫結和繫結事件監聽事件
- class 和 style 資料動態繫結
- 從單向到雙向資料繫結
- 關於簡單的資料雙向繫結原理,defineProperty 和Proxy演示
- 資料複雜性和簡單
- JS雙向資料繫結JS
- vue資料繫結原始碼Vue原始碼
- [系列] Gin框架 - 資料繫結和驗證框架
- Winform控制元件繫結資料ORM控制元件
- Study Blazor .NET(四)資料繫結Blazor
- Vue資料雙向繫結原理Vue
- angular1資料繫結例子Angular
- vue雙向資料繫結原理Vue
- DataBinding資料繫結基本講解
- 初見SpringMVC之資料繫結SpringMVC
- 原生js雙向資料繫結JS
- uni-app入門教程(3)資料繫結、樣式繫結和事件處理APP事件
- SAP UI5 初學者教程之十九 - SAP UI5 資料型別和複雜的資料繫結UI資料型別
- Vue 中雙向繫結 Vs 單向資料流Vue
- 前端三大框架:資料繫結與資料流前端框架
- 從最簡單的資料劫持瞭解vue雙向繫結原理Vue
- WPF/C#:資料繫結到方法C#
- 雙向資料繫結是什麼
- 如何妙用Spring 資料繫結機制?Spring
- 淺入深出Vue:資料繫結Vue
- 雙向資料繫結實現原理
- javascript實現雙向資料繫結JavaScript