Initial ASP. NET data control [continued ListView]

Source: Internet
Author: User

ListView Control

The ListView control can be used to display data. It also provides editing, deletion, insertion, paging, sorting, and other functions. ListView is the fusion body of the GridView and DataList. It has the function of Editing data in the GridView control and flexible layout of the DataList control. The paging function of the ListView control must be implemented through the DataPager control.

Template of the ListView Control

  • LayoutTemplate: the root template that identifies the main layout of the control. Contains a placeholder object, such as the table row (tr), div, and span elements. This element is replaced by the content defined in the ItemTemplate template or GroupTemplate template.
  • ItemTemplate: indicates the content to be bound to each displayed data.
  • ItemSeparatorTemplate: identifies the content to be presented between items.
  • GroupTemplate: content that identifies the group layout.
  • GroupSeparatorTemplate: identifies the content to be presented between items.
  • EmptyItemTemplate: identifies the content displayed for an empty item when the GroupTemplate is used.
  • EmptyDataTemplate: identifies the content to be presented when data is returned at the end of the data source.
  • SelectedItemTemplate: identifies the content displayed for the selected data item and other items displayed.
  • AIternatingItemTemplate: identifies the content displayed for the alternate items to facilitate the differentiation of consecutive items.
  • EditItemTemplate: identifies the content to be rendered when an item is edited. For data items being edited, The EditItemTemplate template is displayed to replace the ItemTemplate template.
  • InsertItemTemplate: identifies the content to be presented when an item is inserted.

The attributes and common events of the ListView control are not listed one by one. Here I will use a simple example to describe the data display, paging, and sorting functions of the ListView. These functions can be done only by slightly configuring the control. configuration does not mean that writing code cannot be done. Here the configuration is for Illustration 1. lazy 2. nothing except laziness or laziness. It is recommended that you do not be lazy when using the same dishes as me, me? This time .... O (partition _ partition) o

First, create a demo page, put a ListView in, and put a SqlDataSource Data Source Control in it (use this if you are lazy, I admit that I am lazy ). The details are as follows:

Configure the SqlDataSource data source control and assign the SqlDataSource control to the performanceid attribute of the ListView control.

The details are as follows:

What should we do when we finish doing so much? Okay, now that we have implemented so many next steps, I will continue to configure the ListView control as follows:

Select the pagination page and try out any table styles!

Then we have not sorted it yet! Continue to configure the ListView control (click it), and then you will find that it is really too powerful, how powerful it is! As follows:

Next, switch your VS to the HTML source code, find the location of DataPager in the HTML source code, and then place two Button controls from the toolbox at the end of this location (OK, please be lazy !)

Set the text attribute of the two buttons to the sorting name you want, and set the CommandName attribute to Sort. set CommandArgument to the field you want to sort (the field used in data design) as follows:

After writing the script, the running result is as follows:

The goal is achieved, and it is also lazy to directly show that a line of code is not written .....

Here is just a simple understanding. If you want to study it, you still need to find more information in this area.

Previously, the GridView control was briefly mentioned. Later, a friend in a group was able to discuss the Hidden Column values in the GridView control. At that time, because I was initially not directly involved in chatting with friends in the group, I did my research today.

We usually do not want the data exposed on the client to be set to false in the GridView for the Visible attribute of the corresponding column (I say this is usually the case, of course, it is not excluded that you do not want to bind the data to the GridView that you do not want to see on the client or others.) Here is an experiment.

I set the ID column to hidden. Then we put a button and click the button to view the number of the selected information in the database, and display the number of the row in the GridView control on the Web page. Then, write the code for clicking the event as follows:

Using System; using System. collections. generic; using System. linq; using System. web; using System. web. UI; using System. web. UI. webControls; namespace DataShowApplication {public partial class TextDemo: System. web. UI. page {protected void Page_Load (object sender, EventArgs e) {} protected void button#click (object sender, EventArgs e) {string str = string. empty; int rowNo = 0; this. response. write ("the value you want to see is as follows:" + "<br/>"); // traverses all rows in the GridView foreach (GridViewRow row in this. gridView1.Rows) {// get the box value of the check box in the current row bool ischeck = (CheckBox) row. findControl ("cbCheckBox ")). checked; if (ischeck) {// obtain the information Id field of the hidden value string hidecolum_id = this. gridView1.DataKeyNames [0]; // obtain the Hidden Column value int hidevealue = Convert. toInt32 (this. gridView1.DataKeys [rowNo]. value); this. response. write (hidevealue + "<br/>");} rowNo ++;} this. response. write (str );}}}

The running result is as follows:

In this way, you can get the value of the Hidden Column!

For data control, let's take a look at it first. We will study it later ....

 

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.