(转载)DevExpress ASPxGridView 使用文档六:模板
轉(zhuǎn)載請注明出處:http://surfsky.cnblogs.com/
---------------------------------------------------------
-- ASPxGridView 模板
---------------------------------------------------------
ASPxGridView 提供以下幾種自定義的模板視圖
??? EditForm??? 編輯窗口。彈出式或附加在原記錄下面
??? DetailRow?? 詳細(xì)行。點(diǎn)擊后以form方式查看記錄的詳細(xì)信息
??? PreviewRow? 預(yù)覽行。原記錄下進(jìn)行簡短描述
??? DataRow???? 數(shù)據(jù)行視圖。每一行的內(nèi)容位置都是定制的。
??? 注:列模板請參考文檔《ASPxGridView.Column》
數(shù)據(jù)行模板(DataRow, 類似ListView 卡片視圖)
??? <dxwgv:ASPxGridView ID="grid" ClientInstanceName="grid" runat="server" DataSourceID="AccessDataSource1" KeyFieldName="EmployeeID" Width="100%">
??????? <Columns>
??????????? <dxwgv:GridViewDataColumn FieldName="FirstName" VisibleIndex="1" />
??????????? <dxwgv:GridViewDataColumn FieldName="Title" VisibleIndex="4" />
??????????? <dxwgv:GridViewDataColumn FieldName="Notes" Visible="False" />
??????????? <dxwgv:GridViewDataColumn FieldName="LastName" VisibleIndex="2" />
??????????? <dxwgv:GridViewDataColumn FieldName="BirthDate" VisibleIndex="3"/>
??????????? <dxwgv:GridViewDataColumn FieldName="HireDate" VisibleIndex="5"/>
??????? </Columns>
??????? <SettingsPager PageSize="5" />
??????? <Templates>
??????????? <DataRow>
??????????????? <div style="padding:5px">
??????????????????? <table class="templateTable" cellpadding="2" cellspacing="1" >
??????????????????????? <tr>
??????????????????????????? <td rowspan="4"><img alt="" src="CardView.aspx?Photo=<%# Eval("EmployeeID")%>"/></td>
??????????????????????????? <td class="templateCaption">First Name</td>
??????????????????????????? <td><%# Eval("FirstName") %></td>
??????????????????????????? <td class="templateCaption">Last Name</td>
??????????????????????????? <td><%# Eval("LastName")%></td>
????????????????????????????
??????????????????????? </tr>
??????????????????????? <tr>
??????????????????????????? <td class="templateCaption">Title</td>
??????????????????????????? <td colspan="3"><%# Eval("Title")%></td>
??????????????????????? </tr>
??????????????????????? <tr>
??????????????????????????? <td class="templateCaption">Birth Date</td>
??????????????????????????? <td ><%# Eval("BirthDate")%></td>
??????????????????????????? <td class="templateCaption">Hire Date</td>
??????????????????????????? <td><%# Eval("HireDate")%></td>
??????????????????????? </tr>
??????????????????????? <tr>
??????????????????????????? <td colspan="4" style="white-space:normal"><%# Eval("Notes") %> </td>
??????????????????????? </tr>
??????????????????? </table>
??????????????? </div>
??????????? </DataRow>
??????? </Templates>
??? </dxwgv:ASPxGridView>
????
編輯表單模板(EditForm)
??? 示例一:兩個(gè)標(biāo)簽頁,一個(gè)用標(biāo)準(zhǔn)的編輯面板,一個(gè)展示memo字段
??????? <Templates>
??????????? <EditForm>
??????????????? <div style="padding:4px 4px 3px 4px">
??????????????? <dxtc:ASPxPageControl runat="server" ID="pageControl" Width="100%">
??????????????? <TabPages>
??????????????????? <dxtc:TabPage Text="Info" Visible="true">
??????????????????????? <Controls>
??????????????????????????? <dxwgv:ASPxGridViewTemplateReplacement ID="Editors" ReplacementType="EditFormEditors" runat="server"></dxwgv:ASPxGridViewTemplateReplacement>
??????????????????????? </Controls>
??????????????????? </dxtc:TabPage>
??????????????????? <dxtc:TabPage Text="Notes"? Visible="true">
?????????????????????? <Controls>
??????????????????????????? <dxe:ASPxMemo runat="server" ID="notesEditor" Text='<%# Eval("Notes")%>' Width="100%" Height="93px"></dxe:ASPxMemo>
?????????????????????? </Controls>
??????????????????? </dxtc:TabPage>
??????????????? </TabPages>
??????????????? </dxtc:ASPxPageControl>
??????????????? </div>
??????????????? <div style="text-align:right; padding:2px 2px 2px 2px">
??????????????????? <dxwgv:ASPxGridViewTemplateReplacement ID="UpdateButton" ReplacementType="EditFormUpdateButton" runat="server"></dxwgv:ASPxGridViewTemplateReplacement>
??????????????????? <dxwgv:ASPxGridViewTemplateReplacement ID="CancelButton" ReplacementType="EditFormCancelButton" runat="server"></dxwgv:ASPxGridViewTemplateReplacement>
??????????????? </div>
??????????? </EditForm>
??????? </Templates>
??????? protected string GetMemoText() {
??????????? ASPxPageControl pageControl = grid.FindEditFormTemplateControl("pageControl") as ASPxPageControl;
??????????? ASPxMemo memo = pageControl.FindControl("notesEditor") as ASPxMemo;
??????????? return memo.Text;
??????? }
??????? protected void grid_RowUpdating(object sender, DevExpress.Web.Data.ASPxDataUpdatingEventArgs e) {
??????????? e.NewValues["Notes"] = GetMemoText();
??????? }
??????? protected void grid_RowInserting(object sender, DevExpress.Web.Data.ASPxDataInsertingEventArgs e) {
??????????? e.NewValues["Notes"] = GetMemoText();
??????? }
??? 示例二
??????? <Templates>
??????????? <EditForm>
??????????????? <div style="padding:4px 4px 3px 4px">
??????????????????? <table>
??????????????????????? <tr>
??????????????????????????? <% if(!grid.IsNewRowEditing) { %>
??????????????????????????? <td rowspan="4">
??????????????????????????????? <div style="border: solid 1px #C2D4DA; padding: 2px;"><img alt="" src="TwoWayBinding.aspx?Photo=<%# Eval("EmployeeID")%>" /></div>
??????????????????????????? </td>
??????????????????????????? <% } %>
??????????????????????????? <td style="white-space:nowrap">First Name</td>
??????????????????????????? <td style="width:50%"><dxe:ASPxTextBox runat="server" ID="edFirst" Text='<%# Bind("FirstName") %>' Width="100%" /> </td>
??????????????????????????? <td style="white-space:nowrap">Last Name</td>
??????????????????????????? <td? style="width:50%"><dxe:ASPxTextBox runat="server" ID="edLast" Text='<%# Bind("LastName") %>' Width="100%" /> </td>
??????????????????????? </tr>
??????????????????????? <tr>
??????????????????????????? <td>Title</td>
??????????????????????????? <td style="width:100%" colspan="3"><dxe:ASPxTextBox runat="server" ID="edTitle" Text='<%# Bind("Title") %>' Width="100%" /> </td>
??????????????????????? </tr>
??????????????????????? <tr>
??????????????????????????? <td style="white-space:nowrap">Birth Date</td>
??????????????????????????? <td style="width:50%"><dxe:ASPxDateEdit runat="server" ID="edBirth" Value='<%# Bind("BirthDate") %>' Width="100%" /> </td>
??????????????????????????? <td style="white-space:nowrap">Hire Date</td>
??????????????????????????? <td style="width:50%"><dxe:ASPxDateEdit runat="server" ID="edHire" Value='<%# Bind("HireDate") %>' Width="100%" /> </td>
??????????????????????? </tr>
??????????????????????? <tr>
??????????????????????????? <td colspan="4">
??????????????????????????????? <dxe:ASPxMemo runat="server" ID="edNotes" Text='<%# Bind("Notes")%>' Width="100%" Height="100px" />
??????????????????????????? </td>
??????????????????????? </tr>
??????????????????? </table>
??????????????? </div>
??????????????? <div style="text-align:right; padding:2px 2px 2px 2px">
??????????????????? <dxwgv:ASPxGridViewTemplateReplacement ID="UpdateButton" ReplacementType="EditFormUpdateButton" runat="server" />
??????????????????? <dxwgv:ASPxGridViewTemplateReplacement ID="CancelButton" ReplacementType="EditFormCancelButton" runat="server" />
??????????????? </div>
??????????? </EditForm>
??????? </Templates>
預(yù)覽行模板(PreviewRow)
??? <Templates>
??????? <PreviewRow>
??????????? <table style="border:none">
??????????????? <tbody>
??????????????? <tr>
??????????????????? <td style="width:25%;border:none;color:Black"><img alt="" src="Preview.aspx?Photo=<%# Eval("EmployeeID")%>"/></td>
??????????????????? <td style="border:none;"><%# Container.Text %></td>
??????????????? </tr>
??????????????? </tbody>
??????????? </table>
??????? </PreviewRow>????????????
??? </Templates>
細(xì)節(jié)行模板(DetailRow: 主從視圖Master-Detail)
??? <dxe:ASPxCheckBox ID="chkSingleExpanded" runat="server" Text="Keep a single expanded row at a time" AutoPostBack="true" OnCheckedChanged="chkSingleExpanded_CheckedChanged" />
??? <dxwgv:ASPxGridView ID="grid" ClientInstanceName="grid" runat="server" DataSourceID="masterDataSource" KeyFieldName="CustomerID">
??????? <Columns>
?????????? <dxwgv:GridViewDataColumn FieldName="ContactName"? />
?????????? <dxwgv:GridViewDataColumn FieldName="CompanyName"? />
?????????? <dxwgv:GridViewDataColumn FieldName="City"? />
?????????? <dxwgv:GridViewDataColumn FieldName="Country" />
??????? </Columns>?????????
??????? <Templates>
??????????? <DetailRow>
??????????????? 聯(lián)系電話: <b><%# Eval("Phone")%></b>, 傳真: <b><%# Eval("Fax")%></b><br/>
??????????????? <dxwgv:ASPxGridView ID="detailGrid" runat="server" DataSourceID="detailDataSource" KeyFieldName="OrderID" Width="100%"?
??????????????????? OnBeforePerformDataSelect="detailGrid_DataSelect" OnCustomUnboundColumnData="detailGrid_CustomUnboundColumnData">
??????????????????? <Settings ShowFooter="True" />
??????????????????? <SettingsDetail IsDetailGrid="true"/>
??????????????????? <Columns>
??????????????????????? <dxwgv:GridViewDataColumn FieldName="OrderID" />
??????????????????????? <dxwgv:GridViewDataColumn FieldName="OrderDate" />
??????????????????????? <dxwgv:GridViewDataColumn FieldName="ShipName"? />
??????????????????????? <dxwgv:GridViewDataColumn FieldName="Quantity" Name="Quantity" />
??????????????????????? <dxwgv:GridViewDataTextColumn FieldName="UnitPrice" >
??????????????????????????? <PropertiesTextEdit DisplayFormatString="c" />
??????????????????????? </dxwgv:GridViewDataTextColumn>
??????????????????????? <dxwgv:GridViewDataTextColumn FieldName="Total" UnboundType="Decimal">
??????????????????????????? <PropertiesTextEdit DisplayFormatString="c" />
??????????????????????? </dxwgv:GridViewDataTextColumn>
??????????????????? </Columns>
??????????????????? <TotalSummary>
??????????????????????? <dxwgv:ASPxSummaryItem FieldName="CompanyName" SummaryType="Count"/>
??????????????????????? <dxwgv:ASPxSummaryItem FieldName="Total" SummaryType="Sum" DisplayFormat="c"/>
??????????????????????? <dxwgv:ASPxSummaryItem FieldName="Quantity" SummaryType="Sum" />
??????????????????? </TotalSummary>
??????????????? </dxwgv:ASPxGridView>
??????????? </DetailRow>
??????? </Templates>
??????? <SettingsDetail ShowDetailRow="true"/>????????????????
??? </dxwgv:ASPxGridView>
??? <asp:AccessDataSource ID="masterDataSource" runat="server" DataFile="~/App_Data/nwind.mdb"
??????? SelectCommand="SELECT * FROM [Customers]">
??? </asp:AccessDataSource>
??? <asp:AccessDataSource ID="detailDataSource" runat="server" DataFile="~/App_Data/nwind.mdb"?
??????? SelectCommand="SELECT * FROM [Invoices] Where CustomerID = ?">
??????? <SelectParameters>
??????????? <asp:SessionParameter Name="CustomerID" SessionField="CustomerID" Type="String" />
??????? </SelectParameters>
??? </asp:AccessDataSource>
??? 注意: detailGrid.SettingsDetail.IsDetailGrid = true 表明該grid是作為從表的數(shù)據(jù)表格用的
??? // 主表數(shù)據(jù)綁定
??? protected void Page_Load(object sender, EventArgs e)?
??? {
??????? if(!IsPostBack)?
??????? {
??????????? grid.DataBind();
??????????? grid.DetailRows.ExpandRow(0);
??????? }
??? }
??? // 從表數(shù)據(jù)綁定
??? protected void gridDetail_DataBinding(object sender, EventArgs e)
??? {
??????? ASPxGridView grid = sender as ASPxGridView;
??????? if (grid != null)
??????? {
??????????? int i = (int) grid.GetMasterRowKeyValue();
??????????? grid.DataSource = GetProducts(i);
??????? }
??? }
??? // 從表數(shù)據(jù)選擇?
??? protected void detailGrid_DataSelect(object sender, EventArgs e)?
??? {
??????? Session["CustomerID"] = (sender as ASPxGridView).GetMasterRowKeyValue();
??? }
??? // 從表定制列的展示
??? protected void detailGrid_CustomUnboundColumnData(object sender, ASPxGridViewColumnDataEventArgs e)?
??? {
??????? if(e.Column.FieldName == "Total")?
??????? {
??????????? decimal price = (decimal)e.GetListSourceFieldValue("UnitPrice");
??????????? int quantity = Convert.ToInt32(e.GetListSourceFieldValue("Quantity"));
??????????? e.Value = price * quantity;
??????? }
??? }
??? // 控制從表的顯隱
??? protected void chkSingleExpanded_CheckedChanged(object sender, EventArgs e)?
??? {
??????? grid.SettingsDetail.AllowOnlyOneMasterRowExpanded = chkSingleExpanded.Checked;
??????? if(grid.SettingsDetail.AllowOnlyOneMasterRowExpanded)?
??????? {
??????????? grid.DetailRows.CollapseAllRows();
??????? }
??? }
轉(zhuǎn)載于:https://www.cnblogs.com/goole/archive/2011/04/19/2021169.html
總結(jié)
以上是生活随笔為你收集整理的(转载)DevExpress ASPxGridView 使用文档六:模板的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 【CSDN软件工程师能力认证学习精选】P
- 下一篇: Java使用线程并发库模拟弹夹装弹以及发