Đang chuẩn bị liên kết để tải về tài liệu:
ASP.NET 4 Unleased - p 67

Đang chuẩn bị nút TẢI XUỐNG, xin hãy chờ

Using the Repeater and DataList Controls FIGURE 13.4 Editing database records with the Repeater control. LISTING 13.5 EditRepeater.aspx // The name of the primary key column string DataKeyName = “Id”; /// /// Stores the primary keys in ViewState /// Hashtable Keys { get { if (ViewState[“Keys”] == null) ViewState[“Keys”] = new Hashtable(); return (Hashtable)ViewState[“Keys”]; } } From the Library of Wow! eBook Using the Repeater Control 635 /// /// Build the primary key collection /// protected void rptMovies_ItemDataBound(object sender, RepeaterItemEventArgs e) { if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem) { Keys.Add(e.Item.ItemIndex, DataBinder.Eval(e.Item.DataItem, “Id”)); } } /// . | 634 CHAPTER 13 Using the Repeater and DataList Controls FIGURE 13.4 Editing database records with the Repeater control. LISTING 13.5 EditRepeater.aspx @ Page Language C DOCTYPE html PUBLIC - W3C DTD XHTML 1.1 EN http www.w3.org TR xhtml11 DTD xhtml11.dtd script runat server The name of the primary key column string DataKeyName Id summary Stores the primary keys in ViewState summary Hashtable Keys get if ViewState Keys null ViewState Keys new Hashtable return Hashtable ViewState Keys From the Library of Wow eBook Using the Repeater Control 635 summary Build the primary key collection summary protected void rptMovies_ItemDataBound object sender RepeaterltemEventArgs e if e.Item.ItemType ListItemType.Item e.Item.ItemType ListItemType.AlternatingItem Keys.Add e.Item.ItemIndex DataBinder.Eval e.Item.DataItem Id summary Clear the primary keys when Repeater is rebound to its data source summary protected void rptMovies_DataBinding object sender EventArgs e Keys.Clear summary When you click the Update Insert or Delete button this method executes summary protected void rptMovies_ItemCommand object source RepeaterCommandEventArgs e switch e.CommandName case Update UpdateMovie e break case Insert InsertMovie e break case Delete DeleteMovie e break summary Update a movie record summary void UpdateMovie RepeaterCommandEventArgs e 13 From the Library of Wow eBook 636 CHAPTER 13 Using the Repeater and DataList Controls Get the form fields TextBox txtTitle TextBox e.Item.FindControl txtTitle TextBox txtDirector TextBox e.Item.FindControl txtDirector CheckBox chkInTheaters CheckBox e.Item.FindControl chkInTheaters Set the DataSource parameters srcMovies.UpdateParameters Id .DefaultValue Keys e.Item.ItemIndex .ToString srcMovies.UpdateParameters Title .DefaultValue txtTitle.Text srcMovies.UpdateParameters Director .DefaultValue txtDirector.Text srcMovies.UpdateParameters InTheaters .DefaultValue chkInTheaters.Checked.ToString Fire the UpdateCommand srcMovies.Update summary Insert a

TÀI LIỆU LIÊN QUAN