사용자가 선택한 열에 따라 동적으로 데이터 뷰에 추가되는 ASP.Net 데이터 뷰 열 템플릿이 두 개 있습니다.동적으로 추가 된 Web.UI.ITemplate 클래스의 모범 사례
이 템플릿 세포는 사용자 정의 데이터 바인딩을 처리해야합니다
public class CustomColumnTemplate:
ITemplate
{
public void InstantiateIn(Control container)
{
//create a new label
Label contentLabel = new Label();
//add a custom data binding
contentLabel.DataBinding +=
(sender, e) =>
{
//do custom stuff at databind time
contentLabel.Text = //bound content
};
//add the label to the cell
container.Controls.Add(contentLabel);
}
}
...
myGridView.Columns.Add(new TemplateField
{
ItemTemplate = new CustomColumnTemplate(),
HeaderText = "Custom column"
});
는 첫째로이 오히려 지저분 해 보이지만, 자원 문제도있다. Label
이 생성되어 InstantiateIn
에 처리 할 수 없습니다. 그 이유는 데이터 바인드가 없기 때문입니다.
이러한 컨트롤에는 더 좋은 패턴이 있습니까?
데이터 바인딩 후 레이블이 처리되고 렌더링되는지 확인하는 방법이 있습니까?