


Sometimes, when you enter a certain stage of programming and it is very difficult to further improve, you might as well go back and look at the basic things. Maybe you will gain new benefits, and maybe you can truly understand what Confucius said. The true meaning of “reviewing the past and learning the new”.
Commonly used C# data binding controls include: Repeater, DataList, GridView, DetailsView, etc. Here I use Repeater to briefly explain the problem.
Use this property to specify the data source used to fill the Repeater control. DataSource can be any System.Collections.IEnumerable object,
such as System.Data.DataView, System.Collections.ArrayList, System.Collections.Hashtable, array or IListSource object used to access the database.
Commonly used data sources:
A DataTable
A DataView
A DataSet
Any component that implements the IListSource interface
Any component that implements the IList interface
Note:
If To bind to a strongly-typed array of objects, the object type must contain public properties.
The specific applications of DataSource are introduced below through several simple examples.
Binding a DataTable generally involves retrieving data from the database and then binding it directly. The specific database operation logic is no longer provided. Everyone must be very familiar with it. Binding a DataView is similar to this.
Program code
privatevoidBindData() { //通过业务逻辑,直接调用数据库中的数据 DataTablenTable=getTable(); Repeater1.DataSource=nTable; Repeater1.DataBind(); }
HTML code
C#Data binding control program code
<asp:RepeaterIDasp:RepeaterID="Repeater1"runat="server"> <HeaderTemplate> <table> <tr> <thscopethscope="col"> 姓名th> <th> 年龄th> <tr> <HeaderTemplate> <ItemTemplate> <tr> <td> <%#Eval("Key")%> <td> <td> <%#Eval("value")%> <td> <tr> <ItemTemplate> <FooterTemplate> <table><FooterTemplate> <asp:Repeater>
Bind Array, ArrayList, List, one-dimensional array, etc., inside Store simple data.
ArrayList
C#Data binding control program code
privatevoidBindData() { ArrayListlist=newArrayList(); list.Add("Jim"); list.Add("Tom"); list.Add("Bluce"); list.Add("Mary"); Repeater1.DataSource=list; Repeater1.DataBind(); }
HTML appropriate changes
Program code
<asp:RepeaterIDasp:RepeaterID="Repeater1"runat="server"> <HeaderTemplate><table><tr><thscopethscope="col">姓名<th><tr><HeaderTemplate> <ItemTemplate><tr><td><%#Container.DataItem%><td><tr><ItemTemplate> <FooterTemplate><table><FooterTemplate> <asp:Repeater>
Bind Dictionary, HashTable
Dictionary
C#Data binding control program code
privatevoidBindData() { Dictionary<string,int>dic=newDictionary<string,int>(); dic.Add("Jim",21); dic.Add("Tom",26); dic.Add("Bluce",33); dic.Add("Mary",18); Repeater1.DataSource=dic; Repeater1.DataBind(); }
HTML code
Program code
<asp:RepeaterIDasp:RepeaterID="Repeater1"runat="server"> <HeaderTemplate><table><tr><thscopethscope="col">姓名<th><th>年龄<th><tr><HeaderTemplate> <ItemTemplate><tr><td><%#Eval("Key")%>td><td><%#Eval("value")%><td><tr><ItemTemplate> <FooterTemplate><table><FooterTemplate> <asp:Repeater>
Bind object collection, IList, etc. This is very useful. When we perform data query, we often retrieve data from the database. In order to facilitate operation, it needs to be encapsulated into objects. However, sometimes these objects need to be displayed in the form of a list. One solution: object conversion For DataTable, the other is to call the database directly. These two options are not ideal. And here, the object collection is directly bound to the data display control, pointing out a way out for me. In fact, in PetShop4.0, this is used to bind ICollection or IList. easy to understand.
A simple user class containing two public properties.
Program code
usingSystem; usingSystem.Data; /// ///SummarydescriptionforUser /// publicclassUser { privatestring_Name; publicstringName { get{return_Name;} set{_Name=value;} } privateint_Age; publicintAge { get{return_Age;} set{_Age=value;} } publicUser() { // //TODO:Addconstructorlogichere // } publicUser(stringname,intage) { _Name=name; _Age=age; } }
Binding object collection:
IList
Program code
privatevoidBindData() { Useruser1=newUser("Jim",21); Useruser2=newUser("Tom",23); Useruser3=newUser("Bluce",33); Useruser4=newUser("Mary",18); IList<User>list=newList<User>(); list.Add(user1); list.Add(user2); list.Add(user3); list.Add(user4); Repeater1.DataSource=list; Repeater1.DataBind(); }
The public properties of the corresponding Repeater binding object:
C#Data binding Control program code
<asp:RepeaterIDasp:RepeaterID="Repeater1"runat="server"> <HeaderTemplate> <table> <tr> <thscopethscope="col"> 姓名th> <th> 年龄<th> <tr> <HeaderTemplate> <ItemTemplate> <tr> <td> <%#Eval("Name")%> <td> <td> <%#Eval("Age")%> <td> <tr> <ItemTemplate> <FooterTemplate> <table><FooterTemplate> <asp:Repeater>
The above is the content of the DataSource property in the C# data binding control. For more related content, please pay attention to the PHP Chinese website (www.php.cn)!

C#.NET is widely used in the modern world in the fields of game development, financial services, the Internet of Things and cloud computing. 1) In game development, use C# to program through the Unity engine. 2) In the field of financial services, C#.NET is used to develop high-performance trading systems and data analysis tools. 3) In terms of IoT and cloud computing, C#.NET provides support through Azure services to develop device control logic and data processing.

.NETFrameworkisWindows-centric,while.NETCore/5/6supportscross-platformdevelopment.1).NETFramework,since2002,isidealforWindowsapplicationsbutlimitedincross-platformcapabilities.2).NETCore,from2016,anditsevolutions(.NET5/6)offerbetterperformance,cross-

The C#.NET developer community provides rich resources and support, including: 1. Microsoft's official documents, 2. Community forums such as StackOverflow and Reddit, and 3. Open source projects on GitHub. These resources help developers improve their programming skills from basic learning to advanced applications.

The advantages of C#.NET include: 1) Language features, such as asynchronous programming simplifies development; 2) Performance and reliability, improving efficiency through JIT compilation and garbage collection mechanisms; 3) Cross-platform support, .NETCore expands application scenarios; 4) A wide range of practical applications, with outstanding performance from the Web to desktop and game development.

C# is not always tied to .NET. 1) C# can run in the Mono runtime environment and is suitable for Linux and macOS. 2) In the Unity game engine, C# is used for scripting and does not rely on the .NET framework. 3) C# can also be used for embedded system development, such as .NETMicroFramework.

C# plays a core role in the .NET ecosystem and is the preferred language for developers. 1) C# provides efficient and easy-to-use programming methods, combining the advantages of C, C and Java. 2) Execute through .NET runtime (CLR) to ensure efficient cross-platform operation. 3) C# supports basic to advanced usage, such as LINQ and asynchronous programming. 4) Optimization and best practices include using StringBuilder and asynchronous programming to improve performance and maintainability.

C# is a programming language released by Microsoft in 2000, aiming to combine the power of C and the simplicity of Java. 1.C# is a type-safe, object-oriented programming language that supports encapsulation, inheritance and polymorphism. 2. The compilation process of C# converts the code into an intermediate language (IL), and then compiles it into machine code execution in the .NET runtime environment (CLR). 3. The basic usage of C# includes variable declarations, control flows and function definitions, while advanced usages cover asynchronous programming, LINQ and delegates, etc. 4. Common errors include type mismatch and null reference exceptions, which can be debugged through debugger, exception handling and logging. 5. Performance optimization suggestions include the use of LINQ, asynchronous programming, and improving code readability.

C# is a programming language, while .NET is a software framework. 1.C# is developed by Microsoft and is suitable for multi-platform development. 2..NET provides class libraries and runtime environments, and supports multilingual. The two work together to build modern applications.


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Dreamweaver Mac version
Visual web development tools

WebStorm Mac version
Useful JavaScript development tools

Dreamweaver CS6
Visual web development tools

SublimeText3 English version
Recommended: Win version, supports code prompts!

MinGW - Minimalist GNU for Windows
This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.
