MetaTable.Columns 属性
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
获取表的列集合。
public:
property System::Collections::ObjectModel::ReadOnlyCollection<System::Web::DynamicData::MetaColumn ^> ^ Columns { System::Collections::ObjectModel::ReadOnlyCollection<System::Web::DynamicData::MetaColumn ^> ^ get(); };
public System.Collections.ObjectModel.ReadOnlyCollection<System.Web.DynamicData.MetaColumn> Columns { get; }
member this.Columns : System.Collections.ObjectModel.ReadOnlyCollection<System.Web.DynamicData.MetaColumn>
Public ReadOnly Property Columns As ReadOnlyCollection(Of MetaColumn)
一个包含表列的集合。
下面的示例演示如何使用 Columns 属性。 在本示例中,动态数据页模板已复制到 \DynamicData\CustomPages\ProductDescriptions 文件夹,以便为 AdventureWorksLT 数据库的 ProductDescription 表提供自定义显示。 Insert.aspx 文件的标记已更改,以添加 OnDataBound
名为 的 DetailsView1_DataBound
事件处理程序。 在事件处理程序中 FindMetaTable , 方法用于查找元表。 属性 Columns 用于显示表中的列数。
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Linq;
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.Xml.Linq;
using System.Web.DynamicData;
public partial class Insert : System.Web.UI.Page {
protected MetaTable table;
protected void Page_Init(object sender, EventArgs e) {
DynamicDataManager1.RegisterControl(DetailsView1);
}
protected void Page_Load(object sender, EventArgs e) {
table = DetailsDataSource.GetTable();
Title = table.DisplayName;
}
protected void DetailsView1_DataBound(object sender, EventArgs e) {
var dsc = DetailsView1.FindDataSourceControl() as LinqDataSource;
if (dsc == null || dsc.EnableInsert != true)
return;
var mTbl = DetailsView1.FindMetaTable() as MetaTable;
if (mTbl != null)
LblMetaTbl.Text = "Column count = " + mTbl.Columns.Count.ToString();
var fldTmpUsrCtl = DetailsView1.FindFieldTemplate("Description") as FieldTemplateUserControl;
if (fldTmpUsrCtl != null) {
var entryFldDescript = fldTmpUsrCtl.DataControl as TextBox;
entryFldDescript.Text = "(Enter short Description here.)";
}
var fldTmpUsrCtl2 = DetailsView1.FindFieldTemplate("ModifiedDate") as FieldTemplateUserControl;
if (fldTmpUsrCtl2 != null) {
var entryFldModDate = fldTmpUsrCtl2.DataControl as TextBox;
entryFldModDate.Text = System.DateTime.Now.Date.ToShortDateString();
}
}
protected void DetailsView1_ItemCommand(object sender, DetailsViewCommandEventArgs e) {
if (e.CommandName == DataControlCommands.CancelCommandName) {
Response.Redirect(table.ListActionPath);
}
}
protected void DetailsView1_ItemInserted(object sender, DetailsViewInsertedEventArgs e) {
if (e.Exception == null) {
Response.Redirect(table.ListActionPath);
}
}
}
<%@ Page Language="C#" MasterPageFile="~/Site.master" CodeFile="Insert.aspx.cs" Inherits="Insert" %>
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
<asp:DynamicDataManager ID="DynamicDataManager1" runat="server" AutoLoadForeignKeys="true" />
<h2> DynamicData\CustomPages\ProductDescriptions\Insert.aspx <%= table.DisplayName %></h2>
<p> <asp:Label ID="LblMetaTbl" runat="server" Text="Label"></asp:Label> </p>
<asp:ScriptManagerProxy runat="server" ID="ScriptManagerProxy1" />
<asp:ValidationSummary ID="ValidationSummary1" runat="server" EnableClientScript="true"
HeaderText="List of validation errors" />
<asp:DynamicValidator runat="server" ID="DetailsViewValidator" ControlToValidate="DetailsView1" Display="None" />
<asp:DetailsView ID="DetailsView1" runat="server" DataSourceID="DetailsDataSource" DefaultMode="Insert"
AutoGenerateInsertButton="True" OnItemCommand="DetailsView1_ItemCommand" OnItemInserted="DetailsView1_ItemInserted"
CssClass="detailstable" FieldHeaderStyle-CssClass="bold"
OnDataBound="DetailsView1_DataBound">
</asp:DetailsView>
<asp:LinqDataSource ID="DetailsDataSource" runat="server" EnableInsert="true">
</asp:LinqDataSource>
</asp:Content>
产品 | 版本 |
---|---|
.NET Framework | 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1 |