TAILIEUCHUNG - ASP.NET 4 Unleased - p 44

Using the SqlDataSource Control FIGURE Canceling a command when a field is blank. LISTING /// /// Iterate through all parameters and check for null /// protected void srcMovies_Updating(object sender, SqlDataSourceCommandEventArgs e) { foreach (SqlParameter param in ) if ( == null) { = true; = “All fields are required!”; } } From the Library of Wow! eBook Executing Database Commands 405 .error { display:block; color:red; font:bold 16px Arial; margin:10px; } td,th { padding:10px; } Cancel Command. | 404 CHAPTER 9 Using the SqlDataSource Control All fields are required Caiegorvld Director James Cameron DateReleased 6 21 1997 llOftOOAM 345678910 FIGURE Canceling a command when a field is blank. LISTING @ Page Language C @ Import Namespace DOCTYPE html PUBLIC - W3C DTD XHTML EN http TR xhtml11 DTD script runat server summary Iterate through all parameters and check for null summary protected void srcMovies_Updating object sender SqlDataSourceCommandEventArgs e foreach SqlParameter param in if null true All fields are required script html xmlns http 1999 xhtml head id Head1 runat server From the Library of Wow eBook Executing Database Commands 405 style type text css .error display block color red font bold 16px Arial margin 10px td th padding 10px style title Cancel Command title head body form id form1 runat server div asp Label id lblError EnableViewState false CssClass error Runat server asp DetailsView id dtlMovie DataSourceID srcMovies DataKeyNames Id AllowPaging true AutoGenerateEditButton true Runat server asp SqlDataSource id srcMovies SelectCommand SELECT FROM Movies UpdateCommand UPDATE Movies SET Title @Title Director @Director DateReleased @DateReleased WHERE Id @id ConnectionString ConnectionStrings Movies Runat server OnUpdating srcMovies_Updating div form body html 9 From the Library of Wow eBook 406 CHAPTER 9 Using the SqlDataSource Control The page in Listing includes a srcMovies_Updating method. In this method each parameter associated with the update command is compared against the value Nothing null . If one of the parameters is null an error message displays in a Label control. Using Parameters with the SqlDataSource Control You can use any of the following Parameter objects with the SqlDataSource control Parameter Represents an arbitrary static value. ControlParameter Represents

Đã phát hiện trình chặn quảng cáo AdBlock
Trang web này phụ thuộc vào doanh thu từ số lần hiển thị quảng cáo để tồn tại. Vui lòng tắt trình chặn quảng cáo của bạn hoặc tạm dừng tính năng chặn quảng cáo cho trang web này.