Asp.netserver Control Development Grid Implementation (one) UI transfer

Source: Internet
Author: User

Using ASP. Web development time, the control system provides, the purpose, sometimes difficult to achieve the ideal. Then there are several ways to solve, for example, using the Html+js form, at the front end of the layout of the desired interface, and then get the data through Ajax and other means. In order to achieve this goal.

But it's hard to do it. , more strenuous. Someone. The code for that interface will be copied directly. But this will inevitably bring bigger problems for later maintenance. So just think about it. Is there a way to make the layout reusable and easy to maintain. The ASP. NET controls can be easily laid out, and the controls can be manipulated directly in the background at the same time. Implement the relevant data logic. So just want to borrow the technology of ASP, from the line encapsulates the control.

Some people will say. Is it possible to use the user-defined control encapsulation directly from ASP. To a certain extent, it is indeed possible. But let's say we need a lot of other features. This is still very difficult to meet the requirements.

Especially when we use some libraries on the mobile side to develop, the problem is more serious.

For example, when the mobile side uses jquerymobile for development, because Jquerymobile is based on the front-end, it can be tricky to use for the backend. Such a situation. will be able to consider asp.net+jquerymobile to achieve.

(Use ASP. Mvc4 to combine Jquerymobile's non-attribute range)

We pass a simple package. To implement a grid control. Look first.


The preceding code for this is the following:

Front-end Code default.aspx

<%@ page language= "C #" autoeventwireup= "true" codebehind= "Default.aspx.cs" inherits= "Demo._default"%><! DOCTYPE html>The control with the S prefix is the encapsulated grid control.

The following code Default.aspx.cs

Using system;using system.collections.generic;using system.data;using system.linq;using System.Web;using        system.web.ui;using system.web.ui.webcontrols;namespace demo{public partial class _default:system.web.ui.page { protected void Page_Load (object sender, EventArgs e) {if (!            IsPostBack) {initload ();        }} private void Initload () {grid_edit.datasource = Generatedata ();            } private DataTable Generatedata () {DataTable dt = new DataTable (); Dt.            Columns.Add ("NO"); Dt.            Columns.Add ("Type"); Dt.            Columns.Add ("Status"); Dt.            Rows.Add (new string[] {"H10001", "Food", "Sold Out"}); Dt.            Rows.Add (new string[] {"H10002", "vegetables", "Pending Sale"}); Dt.            Rows.Add (new string[] {"H10003", "Fruit", "Pending Sale"}); Dt.            Rows.Add (new string[] {"H10004", "Appliance", "Sales"});        return DT; }    }}
Assigns a value to Grid_edit's datasource.

As you can see from the code, there is a columns inside the S:grid and S:boundfield fields in columns. There are HeaderText and DataField properties in the S:boundfield field.

Among the HeaderText is the column head. DataField is the bound field, corresponding to the DataSource field of the background code.

This works similarly to the GridView.

So we're going to encapsulate a grid, at least a few things:

1. Define a Grid class

2. Include the properties of the columns in the grid class.

3. In the properties of the columns. You must be able to accommodate the BoundField field.

4. You must be able to tap <Columns> directly in the editor.

Detailed implementation, see "Asp.netserver control development of the grid implementation (II)"




Copyright notice: This article blog original articles, blogs, without consent, may not be reproduced.

Asp.netserver Control Development Grid Implementation (one) UI transfer

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.