Using the Repeater and DataList Controls FIGURE Editing database records with the Repeater control. LISTING // 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 ( == || == ) { (, (, “Id”)); } } /// . | 634 CHAPTER 13 Using the Repeater and DataList Controls FIGURE Editing database records with the Repeater control. LISTING @ Page Language C DOCTYPE html PUBLIC - W3C DTD XHTML EN http TR 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 Id summary Clear the primary keys when Repeater is rebound to its data source summary protected void rptMovies_DataBinding object sender EventArgs e summary When you click the Update Insert or Delete button this method executes summary protected void rptMovies_ItemCommand object source RepeaterCommandEventArgs e switch 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 txtTitle TextBox txtDirector TextBox txtDirector CheckBox chkInTheaters CheckBox chkInTheaters Set the DataSource parameters Id .DefaultValue Keys .ToString Title .DefaultValue Director .DefaultValue InTheaters .DefaultValue Fire the UpdateCommand summary Insert a