#眉標=AJAX
#副標=AJAX網頁開發利器(7)
#大標=常用的AJAX控制項實作
#作者=文/圖 王寧疆
==<灰>===========
開始日期:
結束日期:
================
=============
程式1
================
==<灰>===========
================
=============
程式2
protected void Calendar1_SelectionChanged(object sender, EventArgs e)
{
PopupControlExtender1.Commit(
Calendar1.SelectedDate.ToShortDateString());//將使用者於Calendar控制項選取的日期
//填入PopupControlExtender控制項控制的TextBox控制項
Calendar2.SelectedDate = Calendar1.SelectedDate; //指定結束日期必須至少和開始日期相同
}
================
=============
程式3
protected void Calendar2_SelectionChanged(object sender, EventArgs e)
{
PopupControlExtender2.Commit(
Calendar2.SelectedDate.ToShortDateString());//將使用者於Calendar控制項選取的日期
//填入PopupControlExtender控制項控制的TextBox控制項
}
================
==<灰>===========
信用卡:
================
=============
程式4
JCB
================
==<灰>===========
================
=============
程式5
protected void RadioButtonList1_SelectedIndexChanged(object sender, EventArgs e)
{
PopupControlExtender3.Commit(
RadioButtonList1.SelectedValue); //讀取使用者選擇的信用卡,填入到
//PopupControlExtender控制項控制的TextBox控制項中
}
================
==<灰>===========
================
=============
程式6
.ratingStar {
font-size: 0pt;
width: 13px;
height: 12px;
margin: 0px;
padding: 0px;
cursor: pointer;
display: block;
background-repeat: no-repeat;
}
.filledRatingStar {
background-image: url(Images/FilledStar.png);
}
.emptyRatingStar {
background-image: url(Images/EmptyStar.png);
}
.savedRatingStar {
background-image: url(Images/SavedStar.png);
}
================
==<灰>===========
================
=============
程式7
對本篇報導的滿意度:
非常不滿意
不滿意
普通
滿意
非常滿意
================
==<灰>===========
CREATE TABLE [dbo].[Rates] (
[ID] [int] IDENTITY (1, 1) NOT NULL ,
[Article] [nvarchar] (8) COLLATE Chinese_Taiwan_Stroke_CI_AS NOT NULL,
[Rate] [int]
) ON [PRIMARY]
GO
================
==<灰>===========
string strConn = "Data Source=.;Initial Catalog=資料庫名稱;Integrated Security=true;";
================
=============
程式8
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack) //如果網頁是第一次執行
{
string strSQL = "Select Avg(Rate) from Rates where Article='DNET0001'"; //查詢評點的SQL敘述
SqlConnection conn = new SqlConnection(strConn); //建立SqlConnection類別的物件
SqlCommand cmd = new SqlCommand(strSQL, conn); //建立SqlCommand類別的物件
cmd.CommandType = CommandType.Text; //設定SqlCommand類別的物件的CommandType屬性
conn.Open(); //開啟資料庫連線
int Rate=0; //宣告存放評點的變數
try
{
Rate = (int)cmd.ExecuteScalar(); //查詢最新評點資料,並將結果存放到Rate變數中
}
catch (Exception ex) //處理尚無評點記錄的錯誤
{
//do nothing
}
cmd.Dispose(); //丟棄SqlCommand類別的物件
conn.Close(); //關閉資料庫連線
conn.Dispose(); //丟棄SqlConnection類別的物件
Rating1.CurrentRating = Rate; //命令Rating控制項顯示最新的評點資訊
}
}
================
=============
程式9
protected void RadioButtonList1_SelectedIndexChanged(object sender, EventArgs e)
{
int rate = int.Parse(RadioButtonList1.SelectedItem.Value); //取得使用者點選的評點值
string strSQL = "Insert Into Rates(Article, Rate) " +
"Values('DNET0001', " + rate.ToString() + ")"; //新增評點記錄的SQL敘述
SqlConnection conn = new SqlConnection(strConn); //建立SqlConnection類別的物件
SqlCommand cmd = new SqlCommand(strSQL, conn); //建立SqlCommand類別的物件
cmd.CommandType = CommandType.Text; //設定SqlCommand類別的物件的CommandType屬性
conn.Open(); //開啟資料庫連線
cmd.ExecuteNonQuery(); //執行新增評點記錄的動作
cmd.CommandText="Select Avg(Rate) from Rates where Article='DNET0001'";//查詢評點資料的SQL敘述
rate = (int)cmd.ExecuteScalar(); //查詢目前的評點記錄
Rating1.CurrentRating = rate; //將查詢得到的評點資料交給Rating控制項顯示
cmd.Dispose(); //丟棄SqlCommand類別的物件
conn.Close(); //關閉資料庫連線
conn.Dispose(); //丟棄SqlConnection類別的物件
}
================
==<灰>===========
ASP.NET
ADO.NET
Visual C#
Visual Basic
================
==<灰>===========
================
==<灰>===========
================
==<灰>===========
================
==<灰>===========
================
==<灰>===========
================
=============
程式10
================