我認爲模板列的子類將做的工作:
[AspNetHostingPermission(SecurityAction.Demand, Level=AspNetHostingPermissionLevel.Minimal)]
[DefaultProperty("DataField")]
public class DataTemplateField : TemplateField
{
private String _dataField;
public String DataField
{
get {
return _dataField;
}
set {
_dataField = value;
}
}
}
現在u可以使用該領域中的DetailsView這樣
<Fields>
<dvt:DataTemplateField HeaderText="Feld1" DataField="DIS">
<ItemTemplate>
<asp:Button runat="server" Text="Button" />
</ItemTemplate>
</dvt:DataTemplateField>
</Fields>
,並獲得這些數據
protected override void OnPreRender(EventArgs e)
{
base.OnPreRender(e);
foreach(DetailsViewRow row in DetailsView1.Rows)
{
DataControlFieldCell cell = (DataControlFieldCell)row.Cells[1];
if (cell.ContainingField is DataTemplateField)
{
var field = (DataTemplateField)cell.ContainingField;
cell.Enabled = !field.DataField.Equals(fieldToDisable);
}
}
}
怎麼辦你想實現?爲什麼你需要一些額外的數據? – Arthur 2009-09-28 08:22:41
你看過DetailsView上的可用事件嗎? – 2009-09-28 09:32:21
是否有適當的事件? 擴展TemplateField,似乎是最乾淨的方式 – 2009-09-28 10:17:59