GirdView Introduction:
Name: Network View.
Source: GridView is the successor control of DataGrid. In .net framework 2, although DataGrid still exists, GridView has come to the forefront of history, and the trend of replacing DataGrid is inevitable. Don't block.
Function: Its function is to display the data in the data source in the web page. GridView and DataGrid have similar functions. They both display data from the data source on the web page, and display a row of data in the data source, that is, a record, as a row in the output table on the web page.
I will not elaborate on the detailed properties and events of GirdView here. Below I will just briefly introduce how GirdView displays the data searched from the background database, that is, how GirdView binds and displays the data source.
1. The front-end interface is as follows
## 2. Back-end Writing: Use VS to build ASP.NET form applications. Here, I only write the query function. The background code is as follows
1. Establish a database connection
public static SqlConnection createConnection() { SqlConnection con = new SqlConnection("server=.;database=dropDownTest;uid=sa;pwd=123456"); con.Open(); return con; }
2. Write an operation class, which includes ordinary query methods, query methods by conditions, and add methods (omitted)
public static DataTable SelectAll() { SqlConnection con = createConnection(); DataTable dt = new DataTable(); SqlCommand cmd = new SqlCommand("select * from person", con); SqlDataReader sdr = cmd.ExecuteReader(); dt.Load(sdr); return dt; }
3. Write the query button Click event
protected void Button4_Click(object sender, EventArgs e) { string c = ""; //定义空字符串,用来条件查询 //设置复选框1的查询条件 if (this.CheckBox1.Checked) { c = "pID=" + this.txtID.Text; //精确匹配查询条件 } else { c = "pID like'%' "; //模糊匹配查询条件 } if (this.CheckBox2.Checked) { c += " and personName like '%" + this.txtName.Text + "%'"; } if (this.CheckBox3.Checked) { if (RadioButton1.Checked) { c += "and personSex='男'"; } else { c += "and personSex='女'"; } } DataView dv = new DataView(PerosonOperate.SelectAll()); //调用查询方法 dv.RowFilter = c; //设置过滤器(按条件查找) dv.Sort = "pID Desc"; //使结果按照pID字段降序排列 GridView1.DataSource = dv; //设定数据源 GridView1.DataBind(); //绑定数据源 //设置列名,如果不设置,将会以数据库中对应的字段名称代替 GridView1.HeaderRow.Cells[0].Text = "编号"; GridView1.HeaderRow.Cells[1].Text = "姓名"; GridView1.HeaderRow.Cells[2].Text = "性别";
The three query renderings are as follows, namely direct click query, query by gender, query by number and Query name and gender together.
From the filtering of background bound data to the presentation of data in the foreground, the general process of using GridView to display data on the browser is like this. The only thing that is a bit awkward here is the conditional In the query, the spelling of the string is difficult. This is nothing more than using the filtering effect of GirdView, which is this code
dv.RowFilter = c; I hope everyone will be more careful in code writing.
##
The above is the detailed content of Detailed introduction to 'ASP.NET' data binding - GridView. For more information, please follow other related articles on the PHP Chinese website!

Design patterns in C#.NET include Singleton patterns and dependency injection. 1.Singleton mode ensures that there is only one instance of the class, which is suitable for scenarios where global access points are required, but attention should be paid to thread safety and abuse issues. 2. Dependency injection improves code flexibility and testability by injecting dependencies. It is often used for constructor injection, but it is necessary to avoid excessive use to increase complexity.

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.


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

SublimeText3 Mac version
God-level code editing software (SublimeText3)

SublimeText3 Linux new version
SublimeText3 Linux latest version

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment

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

Safe Exam Browser
Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.
