프로그래밍 방식으로 템플릿 필드를 추가하는 GridView가 있습니다. 각 템플릿 필드에는 텍스트 상자가 있습니다. 이 텍스트 상자에 데이터베이스 열에 대한 양방향 바인딩을 만들고 싶습니다. 아래 코드를 참조하십시오.프로그래밍 방식으로 템플릿 필드에 텍스트 상자를 양방향 바인딩하는 방법
public class CustomEditItemTemplate : ITemplate
{
private DataControlRowType templateType;
private string columnName;
public CustomEditItemTemplate(DataControlRowType type, string colname)
{
this.templateType = type;
this.columnName = colname;
}
public void InstantiateIn(System.Web.UI.Control container)
{
TextBox tb = new TextBox();
tb.ID = columnName;
tb.DataBinding += new EventHandler(this.tb_DataBinding);
container.Controls.Add(tb);
}
private void tb_DataBinding(Object sender, EventArgs e)
{
TextBox t = (TextBox)sender;
DetailsView dv = (DetailsView)t.NamingContainer;
//This line does only one way binding. It takes the rows from the database and displays
//them in the textboxes. The other way binding is not done. This is why my code fails
t.Text = DataBinder.Eval(dv.DataItem, columnName).ToString();
}
} 내가 텍스트를 편집 할 때, 이러한 변경이 데이터베이스에 반영하는 텍스트 상자는 할 수있는 방법
tf = new TemplateField();
tf.HeaderText = "My First Names";
tf.EditItemTemplate = new CustomEditItemTemplate(DataControlRowType.DataRow, "firstName");
dvModify.Fields.Add(tf);
을 다음과 같이 내가 위의 클래스를 호출하고있어
게다가? 당신의 시간 모두