看起來我正在尋找的是<asp:Repeater>
,由於它沒有<EditItemTemplate>
,因此只需額外編輯一些代碼即可。
的.ascx
<asp:Repeater id="rItems" runat="server" OnItemCommand="rItems_ItemCommand" OnItemDataBound="rItems_ItemDataBound">
<HeaderTemplate>
<table>
<thead>...</thead>
</HeaderTemplate>
<ItemTemplate>
<tbody id="itemRows" runat="server">
...
<asp:Button ... CommandName="Edit" />
...
</tbody>
<tbody id="editItemRows" runat="server" visible="false">...</tbody>
</ItemTemplate>
<FooterTemplate>
</table>
</FooterTemplate>
</asp:Repeater>
.ascx.cs
private int m_editIndex = -1;
protected void rItems_ItemCommand(object sender, RepeaterCommandEventArgs e)
{
switch (e.CommandName)
{
case "Edit":
m_editIndex = e.Item.ItemIndex;
break;
... // Cancel, Update, Delete, etc
case "Cancel":
m_editIndex = -1;
break;
}
BindItemsDataSource();
}
protected void rItems_ItemDataBound(object sender, RepeaterItemEventArgs e)
{
if (e.Item.ItemType == ListItemType.Item | e.Item.ItemType == ListItemType.AlternatingItem)
{
bool edit = e.Item.ItemIndex == m_editIndex;
HtmlGenericControl tbody = e.Item.FindControl("itemRows") as HtmlGenericControl;
tbody.Visible = !edit;
tbody = e.Item.FindControl("editItemRows") as HtmlGenericControl;
tbody.Visible = edit;
if (edit)
{
PopulateEditableFieldValues(e.Item);
}
}
}
你不需要爲這就是你需要做的是一個自定義的控制'GOOGLE的DataGridView ItemTemplate'有很多在Stackoverflow上以及在互聯網上的工作示例..這就是'你需要創建' – MethodMan 2015-02-09 19:17:52
它看起來像'DataGrid's允許你模板每一列。我需要模板整個行。每個項目將呈現一個2到3行之間的'tbody',每行有不同數量的列('colspan ='x'')。我錯過了什麼,或者'DataGrid'沒有這個功能? – dfoverdx 2015-02-09 19:23:06