asp.net 4.0 forms.asp.net 버튼을 클릭하여 Gridview 항목 템플릿을 동적으로 생성
테이블 ID 키에 연결된 버튼으로 Gridview를 동적으로 생성해야합니다.
는 그래서있는 gridview를 설정하고 열을 추가하기 시작 : 다음
private void SetupGV()
{
try
{ //0
TemplateField tf = new TemplateField();
tf.HeaderText = "X";
tf.ItemTemplate = new AddToItemTemplate();
GV.Columns.Add(tf);
//1
BoundField b = new BoundField();
b.DataField = "FullName";
b.HeaderText = @"Staff/Role";
GV.Columns.Add(b);
....
내가 작성을 ITemplate AddToItemTemplate을 :
public class AddToItemTemplate : ITemplate
{
public AddToItemTemplate(){}
public void InstantiateIn(Control container)
{
ImageButton ib = new ImageButton();
ib.ImageUrl = "~/Content/CIDimg/action4.gif";
ib.Command += ib_Command;
ib.CommandName = "delete";
container.Controls.Add(ib);
}
void ib_Command(object sender, CommandEventArgs e)
{
string s = e.CommandArgument.ToString();
}
#endregion
}
을 내가 GV_RowDataBound 내 ID를 수집하고 이미지 버튼의 명령으로 설정 인수는 문제 없습니다.
모두 제대로 작동하지만 ib_Command은 ITemplate의 일부이므로 정적입니다. 페이지 컨트롤이나 페이지 인스턴스 변수에 액세스 할 수 없습니다.
ASPX 마크 업 파일에 gridview가 생성 될 때 "oncommand"태그를 사용하는 것처럼 페이지 메서드에 버튼 (ib.command + =)을 연결하는 방법이 있습니까?
왜 AddToItemTemplate이 필요하면로드 많은 컨트롤이해야합니까을 수행 할 수있는 gridview의 RowCommand 이벤트에서 지금의
아래로 ButtonField를 추가 할 수 있습니까? –
아니요, 템플릿을 만들지 않고 어떻게 할 수 있습니까? – Lambda