📄 example3.aspx
字号:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Example3.aspx.cs" Inherits="Example3" %>
<%@ Register Src="Date.ascx" TagName="Date" TagPrefix="uc1" %>
<!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>Example 3</title>
<link href="cal/popcalendar.css" type="text/css" rel="stylesheet" />
</head>
<body>
<form id="form1" runat="server">
<div>
<h2>Example 3: Data-binding in GridView</h2>
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataSourceID="dsPersons" CellPadding="4" ForeColor="#333333" GridLines="None" DataKeyNames="Id">
<Columns>
<asp:BoundField DataField="FirstName" HeaderText="First name" />
<asp:BoundField DataField="LastName" HeaderText="Last name" />
<asp:TemplateField HeaderText="Birthdate">
<EditItemTemplate>
<uc1:Date ID="Date1" runat="server" CalendarDate='<%# Bind("Birthdate") %>' />
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%# Bind("Birthdate", "{0:dd.MM.yyyy}") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:CommandField ShowEditButton="True" />
</Columns>
<FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
<RowStyle BackColor="#EFF3FB" />
<PagerStyle BackColor="#2461BF" ForeColor="White" HorizontalAlign="Center" />
<SelectedRowStyle BackColor="#D1DDF1" Font-Bold="True" ForeColor="#333333" />
<HeaderStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
<EditRowStyle BackColor="#2461BF" />
<AlternatingRowStyle BackColor="White" />
</asp:GridView>
<asp:ObjectDataSource ID="dsPersons" runat="server"
SelectMethod="GetPersons" TypeName="DataLayer" UpdateMethod="UpdatePerson">
<UpdateParameters>
<asp:Parameter Name="id" Type="Int32" />
<asp:Parameter Name="firstName" Type="String" />
<asp:Parameter Name="lastName" Type="String" />
<asp:Parameter Name="birthdate" Type="DateTime" />
</UpdateParameters>
</asp:ObjectDataSource>
<p>
This example uses the date picker within a <strong><span style="color: #0000ff">GridView</span></strong>
control. Click on the "Edit" link on a row in the grid to switch into edit mode.</p>
<p>
Note that the "Birthdate" column is a template column and the date picker has been
placed into the "EditItemTemplate". Unfortunately data-binding cannot be set via
the visual designer, so you have to edit the code by hand:</p>
<p>
<span style="font-size: 10pt; font-family: Courier New"><strong><span style="color: #0000ff">
<</span><span style="color: #990000">uc1</span><span style="color: #0000ff">:</span><span
style="color: #990000">Date</span> <span style="color: #ff0000">ID</span><span style="color: #0000ff">="Date1"</span> <span style="color: #ff0000">runat</span><span style="color: #0000ff">="server"</span> <span style="color: #ff0000">CalendarDate</span><span
style="color: #0000ff">='</span><span style="background-color: #ffff33"><%<span
style="background-color: #ffffff"># Bind("Birthdate") </span>%></span><span style="color: #0000ff">'
/></span></strong></span></p>
<p>
<a href="Default.aspx">Back</a></p>
</div>
</form>
</body>
</html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -