-
-
-
-
-
-
-
-
:
-
-






_________
.


 
DetailsView.

DetailsView.


DetailsView ASP.NET 2.0. , GridView . Access: GridView, Columnar DetailsView. , GridView, DetailsView , , . CompositeDataBoundControl.

Visual Studio 2005 , , Smart Tag, , , .

DetailsView, Northwind, Employees.


<asp:DetailsView ID="DetailsView1" runat="server" AutoGenerateRows="False" DataSourceID="SqlDataSource1"
Height="50px" Width="561px" BackColor="White" BorderColor="#DEDFDE" BorderStyle="None" BorderWidth="1px" CellPadding="4" GridLines="Vertical" ForeColor="Black" AllowPaging="True">
<Fields>
<asp:BoundField DataField="LastName" HeaderText="LastName" SortExpression="LastName" />
<asp:BoundField DataField="FirstName" HeaderText="FirstName" SortExpression="FirstName" />
<asp:BoundField DataField="Title" HeaderText="Title" SortExpression="Title" />
<asp:BoundField DataField="TitleOfCourtesy" HeaderText="TitleOfCourtesy" SortExpression="TitleOfCourtesy" />
<asp:BoundField DataField="BirthDate" HeaderText="BirthDate" SortExpression="BirthDate" />
<asp:BoundField DataField="HireDate" HeaderText="HireDate" SortExpression="HireDate" />
<asp:BoundField DataField="Address" HeaderText="Address" SortExpression="Address" />
<asp:BoundField DataField="City" HeaderText="City" SortExpression="City" />
<asp:BoundField DataField="Notes" HeaderText="Notes" SortExpression="Notes" />
<asp:BoundField DataField="HomePhone" HeaderText="HomePhone" SortExpression="HomePhone" />
<asp:BoundField DataField="Country" HeaderText="Country" SortExpression="Country" />
<asp:BoundField DataField="PostalCode" HeaderText="PostalCode" SortExpression="PostalCode" />
<asp:BoundField DataField="Region" HeaderText="Region" SortExpression="Region" />
</Fields>
<FooterStyle BackColor="#CCCC99" />
<EditRowStyle BackColor="#CE5D5A" Font-Bold="True" ForeColor="White" />
<RowStyle BackColor="#F7F7DE" />
<PagerStyle BackColor="#F7F7DE" ForeColor="Black" HorizontalAlign="Right" />
<HeaderStyle BackColor="#6B696B" Font-Bold="True" ForeColor="White" />
<AlternatingRowStyle BackColor="White" />
</asp:DetailsView>
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:NorthwindConnectionString3 %>"
SelectCommand="SELECT [LastName], [FirstName], [Title], [TitleOfCourtesy], [BirthDate], [HireDate], [Address], [City], [Extension], [ReportsTo], [Photo], [Notes], [HomePhone], [Country], [PostalCode], [Region] FROM [Employees]" ProviderName="<%$ ConnectionStrings:NorthwindConnectionString3.ProviderName %>"></asp:SqlDataSource>


:



Mocha.
GridView. PageSize DetailsView . , . PagerSettings:Mode NumericFirstLast.


<PagerSettings FirstPageImageUrl="~/RW_btn.gif" LastPageImageUrl="~/FF_btn.gif" Mode=" NumericFirstLast "
NextPageImageUrl="~/fwd_btn.gif" PreviousPageImageUrl="~/back_btn.gif" />




. CorelDraw 11. , , .

BoundField , GridView, , .
GridView

, GridView , DetailsView .

, SqlDataSource, ConnectionString.
, :


<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:NorthwindConnectionString %>"
SelectCommand="SELECT * FROM [Employees]"
ProviderName="<%$ ConnectionStrings:NorthwindConnectionString.ProviderName %>">


Web.config:


<add name="NorthwindConnectionString" connectionString="Data Source=.SQLExpress;Initial Catalog=Northwind;Integrated Security=True;Pooling=False"


providerName="System.Data.SqlClient" />


SqlDataSource1 GridView, .


<asp:GridView ID="GridView1" runat="server" AllowPaging="True" AutoGenerateColumns="False" CellPadding="4" DataSourceID="SqlDataSource1" ForeColor="#333333" GridLines="None" AllowSorting="True" PageSize="3" DataKeyNames="EmployeeID" SelectedIndex="0">
<FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
<RowStyle BackColor="#EFF3FB" />
<SelectedRowStyle BackColor="#D1DDF1" Font-Bold="True" ForeColor="#333333" />
<PagerStyle BackColor="#2461BF" ForeColor="White" HorizontalAlign="Center" />
<HeaderStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
<AlternatingRowStyle BackColor="White" />
<Columns>
<asp:CommandField ShowSelectButton="True" />
<asp:BoundField DataField="LastName" HeaderText="" SortExpression="LastName" />
<asp:BoundField DataField="FirstName" HeaderText="" SortExpression="FirstName" />
</Columns>
<EditRowStyle BackColor="#2461BF" />
</asp:GridView>


SelectedIndex="0", DetailsView .

SqlDataSource EmployeeID.


<asp:SqlDataSource ID="SqlDataSource2" runat="server"
SelectCommand="SELECT * FROM [Employees] WHERE ([EmployeeID]=@EmployeeID)"
ConnectionString="<%$ ConnectionStrings:NorthwindConnectionString %>" >
<SelectParameters>
<asp:ControlParameter ControlID="GridView1" Name="EmployeeID"
PropertyName="SelectedValue" Type="String" />
</SelectParameters>
</asp:SqlDataSource>


SelectParameters. SelectCommand EmployeeID , GridView1.


<asp:DetailsView ID="DetailsView1" runat="server"
DataSourceID="SqlDataSource2"
Height="50px" Width="561px"
CellPadding="4" GridLines="None" ForeColor="#333333"
HeaderText=" "
AutoGenerateRows="False" DataKeyNames="EmployeeID">
<Fields>
<asp:BoundField DataField="LastName" HeaderText="" SortExpression="LastName" />
<asp:BoundField DataField="FirstName" HeaderText="" SortExpression="FirstName" />
<asp:BoundField DataField="Title" HeaderText="" SortExpression="Title" />
<asp:BoundField DataField="BirthDate" HeaderText=" " SortExpression="BirthDate" />
<asp:BoundField DataField="HireDate" HeaderText=" " SortExpression="HireDate" />
<asp:BoundField DataField="HomePhone" HeaderText="" SortExpression="HomePhone" />
</Fields>
<FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
<EditRowStyle BackColor="#2461BF" />
<RowStyle BackColor="#EFF3FB" />
<PagerStyle BackColor="#2461BF" ForeColor="White" HorizontalAlign="Center" />
<HeaderStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
<AlternatingRowStyle BackColor="White" />
<CommandRowStyle BackColor="#D1DDF1" Font-Bold="True" />
<FieldHeaderStyle BackColor="#DEE8F5" Font-Bold="True" />
</asp:DetailsView>




DetailsView

DetailsView ,

AutoGenerateInsertButton="True". New. , TextBox-.

. SqlDataSource

1. InsertCommand
2. InsertParameter .


<asp:SqlDataSource ID="SqlDataSource2" runat="server"
SelectCommand="SELECT * FROM [Employees] WHERE ([EmployeeID]=@EmployeeID)"
InsertCommand="INSERT INTO [Employees] ( [LastName],
[FirstName], [Title], [BirthDate], [HireDate], [HomePhone])
VALUES ( @LastName,
@FirstName, @Title, @BirthDate, @HireDate, @HomePhone)"
ConnectionString="<%$ ConnectionStrings:NorthwindConnectionString %>" >
<SelectParameters>
<asp:ControlParameter ControlID="GridView1" Name="EmployeeID"
PropertyName="SelectedValue"
/>
</SelectParameters>
<InsertParameters>
<asp:Parameter Type="String" Name="CustomerID"></asp:Parameter>
<asp:Parameter Type="String" Name="LastName"></asp:Parameter>
<asp:Parameter Type="String" Name="FirstName"></asp:Parameter>
<asp:Parameter Type="String" Name="Title"></asp:Parameter>
<asp:Parameter Type="String" Name="BirthDate"></asp:Parameter>
<asp:Parameter Type="String" Name="HireDate"></asp:Parameter>
<asp:Parameter Type="String" Name="HomePhone"></asp:Parameter>
</InsertParameters>
</asp:SqlDataSource>


, ? :)

GridView, . ItemInserted.


protected void DetailsView1_ItemInserted(object sender, DetailsViewInsertedEventArgs e)
{
GridView1.DataBind();
}


.

. .


<asp:TemplateField HeaderText=" " SortExpression="HireDate">
<EditItemTemplate>
<asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("HireDate") %>'></asp:TextBox>
</EditItemTemplate>
<InsertItemTemplate>
<asp:Calendar ID="CalendarHireDate" runat="server"
BackColor="#EFF3FB" ForeColor="#003399"
SelectedDate='<%# Bind("HireDate") %>'></asp:Calendar>
</InsertItemTemplate>
<ItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%# Bind("HireDate") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>


, , .


<asp:Parameter Type="DateTime" Name="HireDate"></asp:Parameter>


, GridView.

Bind, Eval, , , .

DetailsView ASP .NET 2.0.
DetailsView

DetailsView , , , .

ItemCreated

ItemDeleting - ItemDeleted

ItemInserted - ItemInserting

ItemUpdated - ItemUpdating

ModeChanged - ModeChanging

Employees , AllowNulls=false. , , . , ItemInserting . ModeChanged, . ))


protected void DetailsView1_ModeChanged(object sender, EventArgs e)
{
switch (DetailsView1.CurrentMode)
{
case DetailsViewMode.Insert:
DetailsView1.HeaderText = ", , . .";
DetailsView1.HeaderStyle.ForeColor = System.Drawing.Color.Purple;
DetailsView1.HeaderStyle.BackColor = System.Drawing.Color.AliceBlue;
break;
case DetailsViewMode.ReadOnly:
DetailsView1.HeaderText = " ";
DetailsView1.HeaderStyle.ForeColor = System.Drawing.Color.White;
DetailsView1.HeaderStyle.BackColor = System.Drawing.Color.FromArgb(0x507CD1);
break;
}
}




DetailsView1 - , 0 1 1 . , .


protected void DetailsView1_ItemInserting(object sender, DetailsViewInsertEventArgs e)
{
TextBox textbox1 = (TextBox)DetailsView1.Rows[0].Controls[1].Controls[0];
textbox1.Text.Trim();
TextBox textbox2 = (TextBox)DetailsView1.Rows[1].Controls[1].Controls[0];
textbox2.Text.Trim();
if (textbox1.Text == "" || textbox2.Text == "")
e.Cancel= true;
}


DetailsView

, . , DetailsView (, ).

Repeater. DetailsView. Employees, . DetailsView? , . , EmployeeID.


<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:NorthwindConnectionString1 %>"
SelectCommand="SELECT * FROM [Employees] ">
</asp:SqlDataSource>
<br>
<asp:Repeater ID="Repeater1" runat="server" DataSourceID="SqlDataSource1" OnItemCreated="Repeater1_ItemCreated">
<ItemTemplate>
<%# DataBinder.Eval(Container.DataItem, "TitleOfCourtesy") %>
<%# DataBinder.Eval(Container.DataItem, "FirstName") %>
<%# DataBinder.Eval(Container.DataItem, "LastName") %> was born in
<%# ((DateTime)DataBinder.Eval(Container.DataItem, "BirthDate")).ToLongDateString() %>. <p>
<p>He/She lives in <%# DataBinder.Eval(Container.DataItem, "City") %>
of the great country <%# DataBinder.Eval(Container.DataItem, "Country") %>. </p>
<p>We appreciate her work as <%# DataBinder.Eval(Container.DataItem, "Title") %>.</p>
<p><%# DataBinder.Eval(Container.DataItem, "Notes") %></p>
<asp:DetailsView ID="DetailsView1" runat="server" AutoGenerateRows="False" DataKeyNames="EmployeeID"
Height="50px" Width="82%">
<Fields>
<asp:BoundField DataField="Address" HeaderText="Address" SortExpression="Address" />
<asp:BoundField DataField="Region" HeaderText="Region" SortExpression="Region" />
<asp:BoundField DataField="PostalCode" HeaderText="PostalCode" SortExpression="PostalCode" />
<asp:BoundField DataField="HomePhone" HeaderText="HomePhone" SortExpression="HomePhone" />
<asp:BoundField DataField="Extension" HeaderText="Extension" SortExpression="Extension" />
<asp:ImageField HeaderText="Photo" DataImageUrlField="PhotoPath">
</asp:ImageField>
</Fields>
</asp:DetailsView>
</ItemTemplate>
<SeparatorTemplate><hr width=80% dir=rtl></SeparatorTemplate>
</asp:Repeater>


ItemCreated, , DetailsView .


protected void Repeater1_ItemCreated(object sender, RepeaterItemEventArgs e)
{
if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
{
SqlDataSource sds = new SqlDataSource();
sds.ConnectionString = SqlDataSource1.ConnectionString;
sds.ID = "SqlDataSource2";
string Filter = String.Format("where EmployeeID = '{0}'", ((DataRowView)e.Item.DataItem)["EmployeeID"]);
sds.SelectCommand = "SELECT * FROM [Employees] " + Filter;
e.Item.Controls.Add(sds);
System.Web.UI.WebControls.DetailsView ds = (System.Web.UI.WebControls.DetailsView)e.Item.FindControl("DetailsView1");
if (ds != null)
ds.DataSourceID = sds.ID;
}


DetailsView BulletedList, DropDownList .

, , DetailsView , , .


:
: aspnetmania.com