datalist我的示例

发表于:2007-06-30来源:作者:点击数: 标签:
%@ Page Language= VB % !DOCTYPE html PUBLIC -//W3C//DTD XHTML 1.1//EN http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd script runat=server Sub DataList1_ItemCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataListCommandEve
<%@ Page Language="VB" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">

<script runat="server">
Sub DataList1_ItemCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataListCommandEventArgs)
If e.CommandSource.ID = "LinkButton1" Then
DataList1.SelectedIndex = e.Item.ItemIndex
@# ElseIf e.CommandSource.ID = "LinkButton2" Then

@# ElseIf e.CommandSource.ID = "LinkButton4" Then
@# DataList1.EditItemIndex = e.Item.ItemIndex
ElseIf e.CommandSource.ID = "LinkButton3" Then
DataList1.EditItemIndex = -1
ElseIf e.CommandSource.ID = "LinkButton5" Then
Response.Write("hello")
End If

DataList1.DataBind()
End Sub

Sub DataList1_EditCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataListCommandEventArgs)
DataList1.EditItemIndex = e.Item.ItemIndex
DataList1.DataBind()
End Sub

Sub DataList1_CancelCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataListCommandEventArgs)
Response.Write("this is test..................dingding")
DataList1.SelectedIndex = -1
DataList1.DataBind()
End Sub
</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:DataList ID="DataList1" Runat="server" DataKeyField="ID" DataSourceID="Aclearcase/" target="_blank" >ccessDataSource1" OnItemCommand="DataList1_ItemCommand" OnEditCommand="DataList1_EditCommand" OnCancelCommand="DataList1_CancelCommand">
<SelectedItemTemplate>
ID:
<asp:Label ID="Label1" Runat="server" Text=@#<%# Eval("ID") %>@#></asp:Label>&nbsp;
<br />
art_title:
<asp:Label ID="Label2" Runat="server" Text=@#<%# Eval("art_title") %>@#></asp:Label><br />
IP:
<asp:Label ID="Label3" Runat="server" Text=@#<%# Eval("IP") %>@#></asp:Label>
<asp:LinkButton ID="LinkButton2" Runat="server" CommandName="cancel">return</asp:LinkButton>
<asp:LinkButton ID="LinkButton4" Runat="server" CommandName="edit">edit</asp:LinkButton>
<br />
<br />
</SelectedItemTemplate>
<ItemTemplate>
ID:
<asp:Label ID="IDLabel" Runat="server" Text=@#<%# Eval("ID") %>@#></asp:Label>
<asp:LinkButton ID="LinkButton1" Runat="server" >more</asp:LinkButton>
<br />
<br />
</ItemTemplate>
<EditItemTemplate>
ID:&nbsp;&nbsp;
<asp:TextBox ID="TextBox1" Runat="server" Text=@#<%# Eval("ID") %>@#></asp:TextBox>
<br />
art_title:&nbsp;
<asp:TextBox ID="TextBox2" Runat="server" Text=@#<%# Eval("art_title") %>@#></asp:TextBox>
<br />
IP:&nbsp;
<asp:TextBox ID="TextBox3" Runat="server" Text=@#<%# Eval("IP") %>@#></asp:TextBox>
<br /><asp:LinkButton ID="LinkButton3" Runat="server">CANCER</asp:LinkButton>
<asp:LinkButton ID="LinkButton5" Runat="server">SUBMIT</asp:LinkButton>
<br />
</EditItemTemplate>
</asp:DataList>
<asp:AccessDataSource ID="AccessDataSource1" Runat="server" DataFile="~/Data/database.mdb"
SelectCommand="SELECT [ID], [art_title], [IP] FROM [articles]">
</asp:AccessDataSource>

</div>
</form>
</body>
</html>


原文转自:http://www.ltesting.net