Asp+ Learning Notes 3

Source: Internet
Author: User
Tags add object eval reference string
asp+| note 8). Customization of data access
In addition to the DataGrid, there are DataList and Repeater, which can be more flexible to use, but you need to provide templates,
Using the control templates
They also have attribute datasource, which can be assigned to a ICollection object, the ItemTemplate control specifies each record
The appearance of showing, example:
<asp:repeater id= "MyRepeater" runat= "Server" >
<template name= "ItemTemplate" >
<%# DataBinder.Eval (Container.DataItem, "name")%>
</template>
</ASP:Repeater>
Where: Container represents the first control containing System.Web.UI.INamingContainer outside the control, in this case
is a system.web.ui.webcontrols,repeateritem that contains a DataItem attribute.
In addition, you can also use HeaderTemplate and FooterTemplate.
DataList has more control, such as his repeatercoumns attribute can specify a line to repeat several times, repeatdirection
Specifies the direction.
Inserting the LinkButton control can cause a select event, in which DataList can be set to specify the event handler OnSelectedIndexChanged property.
Cases:
<asp:datalist id= "DL" onselectedindexchanged= "Dl_select" >
<asp:linkbutton command= "Select" runat= "Server" >
<% #DataBinder. Eval (Container.DataItem.) Title ")%>
</asp:LinkButton>
......

<script language= "C #" runat= "Server" >
void Dl_select (Object Sencer,eventargs E) {
......
}
</script>

Note that there may be multiple events, such as Edit/update/cancel, so you can use a uniform onitemcommand to handle
Judge by command what exactly is the event. Cases:
void Dl_select (Object Src,datalistcommandeventargs E) {
String command= ((LinkButton) e.commandsource). Text;
Switch (command)
{case "discuss": ... break;
Case "ratings": ... break;
}
}
<asp:linkbutton command= "ratings" runat= "Server" >
View ratings
</asp:LinkButton>
Even better, DataList can also support edit and select Templates!!
Cases:
void Mydatalist_edit (Object Sender,datalistcommandeventargs E) {
Mydatalist.edititemindex = (int) E.item,itemindex;
Set who is selected for editing
.../re-fix
}
void Mydatalist_update (Object Sender,datalistcommandeventargs E) {
String Price = ((HtmlInputText) E.item.findcontrol ("Edit_price")). Value;
......
Mydatalist.edititemindex=-1;
}
......
<template name= "EditItemTemplate" >
......
<b>price:</b><input id= "Edit_price" type= "text" >
.
.
.
This can be easily used in the system background maintenance.
Problem, the example in the template has just one control, so FindControls works, but what if there are multiple?
You can traverse through the DataList items collection, such as:
for (int i=0;i<mydatalist.items.count;i++)
String ischecked = ((CheckBox) mydatalist.items[i]. FindControls ("Save")). Checked. ToString ();

<template name= "ItemTemplate" >
<asp:checkbox id= "Save" runat=server>
</template>


9). Commercial controls
。 Application Bin directory
In the ASP components need to register with regsvr32, not convenient remote management, asp+ only need to put in the application of the/bin directory.
<%import namespace= "HelloWorld"%> introduce namespaces, config files to specify which controls to use, for example:
<configuration>
<compilation>
<assemblies>
<add assembly= "System.Data"/>
<add assembly= "System.Web.Services"/>
<add assembly= "System.Drawing"/>
<add assembly= "*"/>
</assemblies>
</compilation>
</configuration>

Of these, the first three are global and the last one is under the bin directory.

10). Write Control
Slightly.
Note that you need to derive from Controls (System.Web.UI.Controls)

11). WebForms Control Reference
Two major categories,
One is System.Web.UI.HtmlControls, which starts with HTML and is displayed on a Web page.
The second is System.Web.UI.WebControls, attached, such as the DataGrid.
Concrete slightly.

12). WebForms An expression reference
<%%> code block,<%=%> also supported.
<script runat= "Server" >
server controls with: <asp:lable ... runat= "Server" >
HTML server controls with: <span id= "message" runat= "Server" >
Data help: <%#%>
Objects: <ob

[1] [2] Next page



Related Article

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.