Mouse Atlas Tour (9): Hands-on Lab 5 Fifth experiment, using data binding and templates to create an Atlas application

Source: Internet
Author: User
This is the last lab in the 5 series !!
In this experiment, we no longer use the master, but create a common ASPX page. This is a standard ASPX page. We do not need to include references to the client script library in Program Is a simple and quick way for colleges and universities! Now, we can add An ASPX page.
In solution manager, right-click the site, select Add new item, and select Web form in the pop-up dialog box. The name is servercontroldemo. aspx, and remove Place code in separate file Box, so that it will not generate Code Pull the Post File. Click Add.
We will kill the automatically generated <SCRIPT> mark.
Then, set the automatically generated <! Change the doctype document type declaration:

<! Doctype HTML public "-// W3C // dtd xhtml 1.0 transitional // en"

Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd>
This is an xhtm transition document statement, which has three parts: one is transition, the other is strict, and the third is framework.
Change the content in <title> to "Experiment 5", and add a reference to the CSS file outside <title> in <Link href = "site.css" rel = "stylesheet" type = "text/CSS"> </link>
The written code is as follows:
<% @ Page Language = "C #" %>

<! Doctype HTML public "-// W3C // dtd xhtml 1.0 transitional // en"
Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd>


<HTML xmlns = "http://www.w3.org/1999/xhtml">
<Head runat = "server">
<Title> Experiment 5 </title>
<LINK rel = "stylesheet" type = "text/CSS" href = "site.css"> </link>
</Head>
<Body>
<Form ID = "form1" runat = "server">
<Div>

</Div>
</Form>
</Body>
</Html>
Now, add the Atlas scriptmanager, button, and datasource controls to the page.
Add <Atlas: scriptmanager in the <div> tag as follows:
<Atlas: scriptmanager id = "mgr1" runat = "server"/>
As we have mentioned in the previous experiment, only one <Atlas: scriptmanager server control can be included in An ASPX page. If this page contains other Atlas server controls, scriptmanager is a server Atlas control used to access all other Atlas server controls on this page.
Add an atlas server button next to <Atlas: scriptmanager. click the button to get the URL list of the company and its company. We can write code based on the Code Automatic awareness function of the vs2005 development environment, or switch to the design view to set its attributes.
Maybe when we write code, the vs2005 development environment will automatically add/> to the mark to close the mark. At this time, we can do this:
In the menu, Click Tools = options, Open Text Editor in the pop-up dialog box, click HTML under the editor, and then click format under the editor, remove the small check mark before the auto insert close tag on the right!
In the design view, we can set the attributes of the Atlas server button. In the attribute panel, set the text to "get list ", click on the attribute panel, and click the small image on the right of actions. In the dialog box that appears, click Add to set its target value to performance1 and method to select, click OK and switch to the Code view. This code is ugly.
<Div>
<Atlas: scriptmanager id = "mgr1" runat = "server"/>
<Atlas: button id = "fillbutton" runat = "server" text = "get list">
<Click>
<Actions>
<Atlas: invokemethodaction method = "select" target = "performance1"> </Atlas: invokemethodaction>
</Actions>
</Click>
</Atlas: button>
</Div>
<Click> specifies the action that will take place when the button is clicked. This is similar to specifying the space of the Atlas server. <Actions> flag declares what will happen in response to the parent event. In this action, Atlas will call the datasource Server Control (we will add this control below). The target attribute specifies the ID of the datasource control. The method Property specifies a special method to call the Web Service bound to datasource. Here, all the data lists are obtained.
Add a data source control. We add an Atlas data source control after <Atlas: button>. The Code is as follows:
<Atlas: datasource runat = "server" id = "datasource1" serviceurl = "~ /Dataservice. asmx "/>
Here we set the ID and serviceurl attributes of the data source control of the Atlas server.
We then use layouttemplate to add an atlas server listview control. We will use it to bind the data source control and use it to display data. This is actually a server control, but it has some attributes and features of Atlas, such as not passing the entire page back and forth between the client and the server. Next to the <Atlas: datasource control, we add a <Atlas: listview control. Set its ID and templateitemcontrolid in the property panel. The Code is as follows:
<Atlas: listview runat = "server" id = "listview1"

 Itemtemplatecontrolid = "templateitem">


write another and its sub-element
Property = "data"/>

datacontext specifies the ID of the data source to be bound to the listview.
two templates are defined in the element. One is the layouttemplate template and the other is the emptytemplate template. The first one is used to display data, and the second one is used to display data when there is no data.
the final code of this page is as follows:
<% @ page Language = "C #" %>

<! Doctype HTML public "-// W3C // dtd xhtml 1.0 transitional // en"
Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd>

<HTML xmlns = "http://www.w3.org/1999/xhtml">
<Head runat = "server">
<Title> Experiment 5 </title>
<LINK rel = "stylesheet" type = "text/CSS" href = "site.css"/>
</Head>
<Body>
<Form ID = "form1" runat = "server">
<Div>
<Atlas: scriptmanager id = "mgr1" runat = "server"/>
<Atlas: button id = "fillbutton" runat = "server" text = "get list">
<Click>
<Actions>
<Atlas: invokemethodaction method = "select" target = "performance1"/>
</Actions>
</Click>
</Atlas: button>
<Atlas: datasource runat = "server" id = "datasource1" serviceurl = "~ /Dataservice. asmx "/>
<Atlas: listview id = "listview1" runat = server itemtemplatecontrolid = "templateitem">
<Bindings>
<Atlas: Binding datacontext = "cece1" datapath = "data"
Property = "data"/>
</Bindings>
<Layouttemplate>
<Ul runat = "server" id = "templateitemparent">
<Li runat = "server" id = "templateitem">
<Strong id = "strong1" runat = "server">
<Atlas: Label runat = "server" id = "namelabel">
<Bindings>
<Atlas: Binding datapath = "name" property = "text"/>
</Bindings>
</Atlas: Label>
</Strong>
<Br/>
<Atlas: hyperlink runat = "server" id = "companyurl">
<Bindings>
<Atlas: Binding datapath = "Description" property = "text"/>
</Bindings>
</Atlas: hyperlink>
</LI>
</Ul>
</Layouttemplate>
<Emptytemplate> no data </emptytemplate>

</Atlas: listview>
</Div>
</Form>
</Body>
</Html>
Press F5 to run the task. First, no data is displayed. Then click the button to pull the data.
Let's take a look at the dataservice. asmx and samplerow. CS codes. You don't know much about generic types.
First read the book ~~~~~~~~~~~~

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.