请教gridview动态添加模版列的问题
我在动态添加的模版列中包含了一TextBox控件,但是没有办法通过gridview1.rows[0].cells[2].FindControls( "txtValue ")访问到textbox控件?到底是为什么,该如何才能访问?
代码如下:
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
for (int i = 0; i < 2; i++)
{
string colName = "分屯点 " + i.ToString();
TemplateField customField = new TemplateField();
customField.ShowHeader = true;
customField.HeaderTemplate = new GridViewTemplate(DataControlRowType.Header, colName);
customField.ItemTemplate = new GridViewTemplate(DataControlRowType.DataRow, " ");
customField.ItemStyle.Width = 200;
GridView1.Columns.Add(customField);
}
}
}
}
public class GridViewTemplate : ITemplate
{
private DataControlRowType templateType;
private string columnName;
public GridViewTemplate(DataControlRowType type, string colname)
{
templateType = type;
columnName = colname;
}
#region ITemplate 成员
void ITemplate.InstantiateIn(Control container)
{
switch (templateType)
{
case DataControlRowType.Header: