The use method of DetailsView in ASP.net

Source: Internet
Author: User
Tags object copy eval insert log log log net string
ASPX page:
Copy CodeThe code is as follows:
<asp:detailsview id= "DetailsView1" runat= "Server" autogeneraterows= "False" height= "50px"
Width= "500px" onmodechanging= "detailsview1_modechanging" onitemdeleting= "detailsview1_itemdeleting"
onitemupdating= "detailsview1_itemupdating" oniteminserting= "detailsview1_iteminserting" >
<Fields>
<asp:templatefield headertext= "ID" >
<ItemTemplate>
<% #Eval ("Id")%>
</ItemTemplate>
<InsertItemTemplate>
<asp:textbox id= "Txtinsertid" text= "Insertid" runat= "Server"/>
</InsertItemTemplate>
<EditItemTemplate>
<% #Eval ("Id")%>
</EditItemTemplate>
</asp:TemplateField>
<asp:templatefield headertext= "Title" >
<ItemTemplate>
<% #Eval ("Title")%>
</ItemTemplate>
<InsertItemTemplate>
<asp:textbox id= "Txtinserttitle" text= "Inserttitle" runat= "Server"/>
</InsertItemTemplate>
<EditItemTemplate>
<asp:textbox id= "Txtedittitle" text= ' <%# Eval ("Title")%> ' runat= ' server '/>
</EditItemTemplate>
</asp:TemplateField>
<asp:templatefield headertext= "Context" >
<ItemTemplate>
<%# Eval ("Logcontext")%>
</ItemTemplate>
<InsertItemTemplate>
<asp:textbox id= "Txtinsertlogcontext" text= "Insertlogcontext" runat= "Server"/>
</InsertItemTemplate>
<EditItemTemplate>
<asp:textbox id= "Txteditlogcontext" text= ' <%# Eval ("Logcontext")%> ' runat= ' server '/>
</EditItemTemplate>
</asp:TemplateField>
<asp:templatefield headertext= "Operations" >
<ItemTemplate>
<asp:button id= "Btnedit" runat= "Server" causesvalidation= "False"
Commandname= "Edit" text= "editor"/>
<asp:button id= "btnnew" runat= "Server" causesvalidation= "False"
Commandname= "new" text= "newly created"/>
<asp:button id= "Btndelete" runat= "Server" causesvalidation= "False"
Commandname= "Delete" text= "Remove" onclientclick= "return confirm (' OK to update this student information? '); "/>
</ItemTemplate>
<InsertItemTemplate>
<asp:button id= "Btninsert" runat= "Server" causesvalidation= "True"
Commandname= "Insert" text= "inserts"/>
<asp:button id= "Btncancel" runat= "Server" causesvalidation= "False"
Commandname= ' Cancel ' text= ' Cancel '/>
</InsertItemTemplate>
<EditItemTemplate>
<asp:button id= "btnupdate" runat= "Server" causesvalidation= "True"
Commandname= "Update" text= "onclientclick=" return confirm (' OK to update this student information? '); "/>
<asp:button id= "BtnCancel2" runat= "Server" causesvalidation= "False"
Commandname= ' Cancel ' text= ' Cancel '/>
</EditItemTemplate>
</asp:TemplateField>
</Fields>
</asp:DetailsView>


CS File:
Copy CodeThe code is as follows:
Using System;
Using System.Data;
Using System.Configuration;
Using System.Web;
Using System.Web.Security;
Using System.Web.UI;
Using System.Web.UI.WebControls;
Using System.Web.UI.WebControls.WebParts;
Using System.Web.UI.HtmlControls;
Using System.Collections.Generic;
public partial class _default:system.web.ui.page
{
protected void Page_Load (object sender, EventArgs e)
{
if (! IsPostBack)
{
Datatobing ();
}
}
private void Datatobing ()
{
This. Detailsview1.datasource = Datagridsource ();
This. Detailsview1.databind ();
}
Private list<log> Datagridsource ()
{
list<log> logs = new list<log> ();
for (int i = 1; i < i++)
{
Log log = new log ();
Log. Id = i;
Log. title = "title" + I;
Log. Logcontext = "Content" + I;
Logs. ADD (log);
}
return logs;
}
public class Log
{
private int id;
public int Id
{
get {return ID;}
set {id = value;}
}
private string title;
public string Title
{
get {return title;}
set {title = value;}
}
private string Logcontext;
public string Logcontext
{
get {return logcontext;}
set {Logcontext = value;}
}
}
protected void Detailsview1_modechanging (object sender, DetailsViewModeEventArgs e)
{
This. Detailsview1.changemode (E.newmode);
Datatobing ();
}
protected void Detailsview1_itemdeleting (object sender, DetailsViewDeleteEventArgs e)
{
Response.Write ("delete operation");
}
protected void Detailsview1_itemupdating (object sender, DetailsViewUpdateEventArgs e)
{
TextBox Tbtitle = (textbox) this. Detailsview1.findcontrol ("Txtedittitle");
TextBox Tblogcontext = (textbox) this. Detailsview1.findcontrol ("Txtedittitle");
Response.Write ("Update operation: Title:" + Tbtitle.text + ": Logcontext:" + tblogcontext.text);
}
protected void Detailsview1_iteminserting (object sender, DetailsViewInsertEventArgs e)
{
Response.Write ("Insert operation:");
}
}


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.