ASP.NET Web Forms User Controls(三)

tingningpower 2002-09-11 05:33:51
<%@ Control ClassName="Pagelet7CS" %>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.SqlClient" %>

<script language="C#" runat="server">

private String _category = "";

public String Category {

get {
return _category;
}
set {
_category = value;
SqlConnection myConnection = new SqlConnection("server=(local)\\NetSDK;database=pubs;Trusted_Connection=yes");
SqlDataAdapter myCommand = new SqlDataAdapter("select * from Titles where type='" + _category + "'", myConnection);

DataSet ds = new DataSet();
myCommand.Fill(ds, "Titles");

MyDataList.DataSource = ds.Tables["Titles"].DefaultView;
MyDataList.DataBind();
}
}

</script>

<span style="font: 12pt 宋体">类别:<%=Category%></span>

<ASP:DataList id="MyDataList" BorderWidth="0" RepeatColumns="2" runat="server">

<ItemTemplate>

<table cellpadding=10 style="font: 10.5pt 宋体">
<tr>
<td valign="top">
<img align="top" src='<%# DataBinder.Eval(Container.DataItem, "title_id", "/quickstart/aspplus/images/title-{0}.gif") %>' >
</td>
<td valign="top">
<b>书名:</b><%# DataBinder.Eval(Container.DataItem, "title") %><br>
<b>类别:</b><%# DataBinder.Eval(Container.DataItem, "type") %><br>
<b>出版商 ID:</b><%# DataBinder.Eval(Container.DataItem, "pub_id") %><br>
<b>价格:</b><%# DataBinder.Eval(Container.DataItem, "price", "$ {0}") %>
</td>
</tr>
</table>

</ItemTemplate>

</ASP:DataList>



应用:


<%@ Register TagPrefix="Acme" TagName="BookList" Src="pagelet7.ascx" %>

<html>


<script language="C#" runat="server">

void Page_Load(Object sender, EventArgs E) {

Page.Controls.Add(new HtmlGenericControl("hr"));

Control c1 = LoadControl("pagelet7.ascx");
((Pagelet7CS)c1).Category = "business";
Page.Controls.Add(c1);

Page.Controls.Add(new HtmlGenericControl("hr"));

Control c2 = LoadControl("pagelet7.ascx");
((Pagelet7CS)c2).Category = "trad_cook";
Page.Controls.Add(c2);

Page.Controls.Add(new HtmlGenericControl("hr"));

Control c3 = LoadControl("pagelet7.ascx");
((Pagelet7CS)c3).Category = "mod_cook";
Page.Controls.Add(c3);
}

</script>

<body style="font: 10.5pt 宋体">

<h3>以编程方式创建用户控件</h3>

</body>
</html>

...全文
79 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
CloneCenter 2002-12-21
  • 打赏
  • 举报
回复
QuickStart 中有。
caosheng 2002-12-21
  • 打赏
  • 举报
回复
你想问什么?
tingningpower 2002-12-21
  • 打赏
  • 举报
回复
tgsergsedg
Scott Worley Publisher: New Riders Publishing First Edition November 15, 2001 ISBN: 0-7357-1135-6, 730 pages Inside ASP.NET Here’s what reviewers are saying about Inside ASP.NET: About the Author Contributing Authors About the Technical Reviewers Acknowledgments Tell Us What You Think! Introduction Who Is This Book For? Contents of the Book I: Introducing ASP.NET 1. An Overview of ASP.NET ASP.NET The .NET Base Class Libraries ASP.NET Web Application Configuration Session and State Management Cache Management ASP.NET Web Application Development Layers Web Forms XML Web Services COM/COM+ Interoperability and Component Services ADO.NET Migration from Classic ASP to ASP.NET Globalization and Localization Enhanced Security 2. Developing Applications with ASP.NET Application Settings Files The Page Syntax Commonly Used Objects and Classes in ASP.NET Tracing ASP.NET Applications ASP.NET Migration Issues Summary 3. Configuring ASP.NET Applications Deploying the web.config Configuration File Using the Configuration Section Analyzing the system.web Configuration Sections Summary II: Core ASP.NET 4. Web Form-Based Development Introduction to Web Forms Web Form Architecture Separating Code from the User Interface Server Controls Validation Controls Summary 5. State Management in ASP.NET What Is State Management? Using ASP.NET Application State Management Summary III: ASP.NET and Data Access 6. Using ADO.NET in ASP.NET Applications Data Access from a Web-Based Perspective ADO and ADO.NET Working with the Main ADO.NET Objects Building Data-Oriented Web Forms Transaction-Enabled ASP.NET Applications Summary 7. Using XML in ASP.NET Applications XML Document Structure How XML Is Used in ASP.NET Other XML Technologies Using XML in Your Application Real-World Examples Summary IV: Advanced Technologies 8. XML Web Service Development in ASP.NET Introduction to XML Web Services Using the SOAP Toolkit with XML Web Services XML Web Service Discovery—Advertising Your Service Using an XML Web Service in ASP.NET Pages Summary 9. Securing ASP.NET Applications Overview of ASP.NET Security Features Applying Security in ASP.NET Applications Inside ASP.NET Security Other Security Considerations Summary 10. Using Component Services with ASP.NET What Are Component Services? Applying Component Services in an ASP.NET Application The business Object Using the business Object Serviced Components Summary 11. Using Messaging Services with ASP.NET Introduction to Messaging Systems Managing MSMQ Message Queues with Windows 2000 Architecture of the .NET Messaging Services Accomplishing Tasks Using MSMQ and .NET Summary 12. Using Directory Services with ASP.NET Introducing Directory Services How Does Active Directory Work? The Benefits of Active Directory Active Directory Technology Summary Summary 13. Localizing and Globalizing ASP.NET Applications What Is Localization? Localizing an ASP.NET Web Application Summary V: Advanced Web Forms 14. Cache Control in ASP.NET ASP.NET Cache Management Page Output Caching Fragment Caching (Partial Page Caching) Request Caching Summary 15. Creating User and Custom Controls for ASP.NET User Controls Introduction to Custom Controls Summary 16. Mobile Device Development with ASP.NET Wireless Application Protocol (WAP) Wireless Markup Language (WML) Enter ASP.NET Summary VI: Putting It All Together 17. Putting It All Together What Is ProjectPal? Installing the ProjectPal Application A Brief Application Walkthrough Application Architecture ProjectPal Service Layers ProjectPal Client Interfaces The ProjectPal Database The ProjectPal Components Inside the ProjectPal Code Summary VII: Appendixes A. An Overview of .NET Multiple Development Platforms Multiple Development Languages .NET Base Class Libraries Common Language Runtime (CLR) Common Type System (CTS) .NET Server Products B. ASP.NET Common Object Reference HttpContext Object (Context Intrinsic Control) The HttpApplication Class The HttpApplicationState Class (Application Intrinsic Object) The HttpSessionState Class ( Session Intrinsic Object) The HttpRequest Class (Request Intrinsic Object) The HttpResponse Class (Response Intrinsic Object) The Server Class ( HttpServerUtility ) SMTPMail API C. ADO Common Object Reference DataSet Object DataTable Object DataColumn Object DataRow Class DataRelation Object DataView Object DataRowView Class OLEDBDATA Objects SQLData … Objects D. HTML Server Control Reference HtmlForm Object— < form> Element HtmlInputText Object— < input> Element HtmlInputHidden Object— < input type=“hidden”> Element HtmlInputCheckbox Object— < input type=”checkbox”> Element HtmlInputRadioButton Object— < input type=“radiobutton”> Element HtmlInputFile Object— < input type=“file”> Element HtmlTextArea Object— < textarea> Element HtmlButton Object— < button> Element HtmlInputButton Object— < input type=“button”> Element HtmlAnchor Object— < a> Element HtmlImage Object— < img> Element HtmlInputImage Object— < input type=“image”> Element HtmlSelect Object— < select> and
Beginning ASP.NET 4 in VB 2010 The most up-to-date and comprehensive introductory ASP.NET book you’ll find on any shelf, Beginning ASP.NET 4 in VB 2010 guides you through Microsoft’s latest technology for building dynamic web sites. This book will enable you to build dynamic web pages on the fly, and assumes only the most basic knowledge of Visual Basic. The book provides exhaustive coverage of ASP.NET, guiding you from your first steps right up to the most advanced techniques, such as querying databases from within a web page and tuning your site for optimal performance. Within these pages, you’ll find tips for best practices and comprehensive discussions of key database and XML principles you need to know in order to be effective with ASP.NET. The book also emphasizes the invaluable coding techniques of object orientation and code-behind, which will start you off on the track to building real-world web sites right from the beginning—rather than just faking it with simplified coding practices. By the time you’ve finished the book, you will have mastered the core techniques and have all the knowledge you need to begin work as a professional ASP.NET developer. What you’ll learn * How to build well-structured ASP.NET applications from the first principles, including how to incorporate data from databases, XML files, web services, and other services. * A solid understanding of key ASP.NET concepts such as master pages, themes, state management, and error handling, and of which techniques work best in which situations. * How to improve the user experience of your pages through the use of ASP.NET AJAX and Silverlight to increase interactivity and provide input validation. Author Information Matthew MacDonald Matthew MacDonald is an author, educator, and MCSD developer who has a passion for emerging technologies. He is a regular writer for developer journals such as Inside Visual Basic, ASPToday, and Hardcore Visual Studio .NET, and he's the author of several books about programming with .NET, including User Interfaces in VB .NET: Windows Forms and Custom Controls, The Book of VB .NET, and .NET Distributed Applications. In a dimly remembered past life, he studied English literature and theoretical physics. Send e-mail to him with praise, condemnation, and everything in between, to p2p@prosetech.com.
Apress 2010 ASP.NET 4 is the latest version of Microsoft's revolutionary ASP.NET technology. It is the principal standard for creating dynamic web pages on the Windows platform. Pro ASP.NET 4 in C# 2010 raises the bar for high-quality, practical advice on learning and deploying Microsoft's dynamic web solution. This new edition is updated with everything you need to master the latest version of ASP.NET, including coverage of ASP.NET MVC, ASP.NET AJAX 4, ASP.NET Dynamic Data, and Silverlight 3. Seasoned .NET professionals Matthew MacDonald and Mario Szpuszta explain how you can get the most from these groundbreaking new technologies. They cover ASP.NET 4 as a whole, illustrating both the brand-new features and the functionality carried over from previous versions of ASP. This book will give you the knowledge you need to code real ASP.NET 4 applications in the best possible style. What you'll learn * Understand why ASP.NET 4 is so special, what its fundamental principles are, the basics of Visual Studio, and how ASP.NET controls are created and how they fit into ASP.NET pages, ultimately creating full applications. * Become familiar with ASP.NET MVC, a new feature that is one of the biggest additions to ASP.NET 4, and understand how to use it and integrate it within your existing ASP.NET applications. * Discover the intricacies of ADO.NET and how to perform data binding to many sources, from databases to file streams to XML. * Learn the various forms of security available and how to best apply them. Once considered the Achilles' heel of all Windows web applications, security has vastly improved and is now a cornerstone of ASP.NET 4. * Examine in detail advanced user interface techniques, including user controls, customer server controls, client-side JavaScript, GDI+, and Silverlight 3. * Understand how to work with web services, an important skill in an increasingly connected world. * Use ASP.NET AJAX 4, with an emphasis on contemporary web development techniques. * Perform development using Internet Information Services 7, Microsoft's premier web hosting platform. amazon link:http://www.amazon.com/exec/obidos/ASIN/1430225297/buythisbooks-20

62,074

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧