我在RowDataBound事件的grideview中添加了一些文本框控件:
protected void gvPriceRange_RowDataBound(object sender, GridViewRowEventArgs e)
{
DataTable dtRange = null;
DataTable dtTemplateType = null;
try
{
dtRange = (DataTable)Session["dtRange"];
dtTemplateType = (DataTable)Session["dtTemplateType"];
if (e.Row.RowType == DataControlRowType.DataRow)
{
for (int i = 0; i < dtRange.Rows.Count; i++)
{
TextBox txtPrice = new TextBox();
txtPrice.ID = "txtPrice" + i;
e.Row.Cells[i + 1].Controls.Add(txtPrice);
}
}
}
}
然后在按钮上单击事件,我必须将文本框值保存在DB中。
protected void btnSavePriceRange_Click(object sender, EventArgs e)
{
DataTable dtRange = null;
DataTable dtTemplateType = null;
MailingProgram mp = null;
try
{
mp = new MailingProgram();
dtRange = (DataTable)Session["dtRange"];
dtTemplateType = (DataTable)Session["dtTemplateType"];
foreach(GridViewRow row in gvPriceRange.Rows)
{
for (int i = 0; i < dtRange.Rows.Count; i++)
{
TextBox txtPrice = (TextBox)row.FindControl("txtPrice"+i);
if (txtPrice != null)
{
}
}
}
}
}
但我没有得到任何文本框的参考。 看着像行一样的行。细胞[1] .HasControls()&#39;返回false,表示gridview没有呈现textBox。 我怎么能得到文本框的参考?