<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm3.aspx.cs" Inherits="WebApplication1.WebForm3" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
protected void
ContactsListView_ItemCreated(object sender, ListViewItemEventArgs e)
{
// Retrieve the
current item.
ListViewItem item = e.Item;
// Verify if
the item is a data item.
if (item.ItemType == ListViewItemType.DataItem)
{
// Get the
EmailAddressLabel Label control in the item.
Label EmailAddressLabel =
(Label)item.FindControl("EmailAddressLabel");
// Display the
email address in italics.
EmailAddressLabel.Font.Italic = true;
}
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="Head1" runat="server">
<title>ListViewItem
Example</title>
<style type="text/css">
body { text-align: Left; }
.bgcolor { background-color: #CAEEFF; }
</style>
</head>
<body style="font: 10pt
Trebuchet MS">
<form id="form1" runat="server">
<h3 >ListViewItem Example</h3>
<asp:ListView ID="ContactsListView"
DataSourceID="ContactsDataSource"
InsertItemPosition="LastItem"
OnItemCreated="ContactsListView_ItemCreated"
runat="server">
<LayoutTemplate>
<table cellpadding="2" width="680px" border="0">
<tr class="bgcolor" runat="server">
<th runat="server">First Name</th>
<th runat="server">Last Name</th>
<th runat="server">Middle Name</th>
<th runat="server">Email Address</th>
<th runat="server">Phone</th>
</tr>
<tr id="itemPlaceholder" runat="server"></tr>
<tr>
<th>
<asp:DataPager runat="server" ID="PeopleDataPager">
<Fields>
<asp:NumericPagerField ButtonCount="10" />
</Fields>
</asp:DataPager>
</th>
</tr>
</table>
</LayoutTemplate>
<ItemTemplate>
<tr runat="server" align ="left">
<td>
<asp:Label ID="FirstNameLabel" runat="server" Text='<%#Eval("FirstName") %>' />
</td>
<td>
<asp:Label ID="LastNameLabel" runat="server" Text='<%#Eval("LastName") %>' />
</td>
<td>
<asp:Label ID="MiddleNameLabel" runat="server" Text='<%#Eval("MiddleName") %>' />
</td>
<td>
<asp:Label ID="EmailAddressLabel" runat="server" Text='<%#Eval("EmailAddress") %>' />
</td>
<td>
<asp:Label ID="PhoneLabel" runat="server" Text='<%#Eval("Phone") %>' />
</td>
</tr>
</ItemTemplate>
<InsertItemTemplate>
<tr class="bgcolor">
<td>
<asp:TextBox ID="FirstName" runat="server"
Text='<%#Bind("FirstName") %>' MaxLength="50" />
</td>
<td>
<asp:TextBox ID="LastName" runat="server"
Text='<%#Bind("LastName") %>' MaxLength="50" /> <br />
</td>
<td>
<asp:TextBox ID="MiddleName" runat="server"
Text='<%#Bind("MiddleName") %>' MaxLength="50" /> <br />
</td>
<td>
<asp:TextBox ID="EmailAddress" runat="server"
Text='<%#Bind("EmailAddress") %>' MaxLength="50" /> <br />
</td>
<td>
<asp:TextBox ID="Phone" runat="server"
Text='<%#Bind("Phone") %>' MaxLength="50" /> <br />
</td>
</tr>
<tr class="bgcolor" runat="server">
<td colspan="5">
<asp:Button ID="InsertButton" runat="server" CommandName="Insert" Text="Insert" />
<asp:Button ID="CancelInsertButton" runat="server" CommandName="Cancel" Text="Cancel" />
</td>
</tr>
</InsertItemTemplate>
</asp:ListView>
<!--
This example uses Microsoft SQL Server and connects -->
<!-- to
the AdventureWorks sample database. Use an ASP.NET -->
<!--
expression to retrieve the connection string value -->
<!--
from the Web.config file. -->
<asp:SqlDataSource ID="ContactsDataSource" runat="server"
ConnectionString="<%$ ConnectionStrings:constr %>"
SelectCommand="SELECT [FirstName] ,[LastName] ,[MiddleName] ,[EmailAddress]
,[Phone]
FROM [AdventureWorksDW2017].[dbo].[DimEmployee]"
InsertCommand="INSERT INTO [AdventureWorksDW2017].[dbo].[DimEmployee]
([FirstName] ,[LastName]
,[MiddleName] ,[EmailAddress] ,[Phone])
Values(@FirstName, @LastName,
@MiddleName, @EmailAddress, @Phone)">
</asp:SqlDataSource>
</form>
</body>
No comments:
Post a Comment