我在formview中有一个gridview。我试图循环通过gridview进行比较,但收到以下错误:“对象引用未设置为对象的实例。”我尝试了不同的东西来在gridview中找到控件,但似乎没有任何工作。以下是我背后代码的代码:
GridView myGridview = (GridView)frmPvdrYr.Row.FindControl("grdPvdrYr");
foreach (GridViewRow row in myGridview.Rows) //prevents duplicate entries from being entered into the table
{
if (row.RowType == DataControlRowType.DataRow)
{
TextBox start_dt = row.FindControl("txtStartDt") as TextBox;
if (start_dt.Text == ((TextBox)frmPvdrYr.Row.FindControl("txtStartDt")).Text || ((TextBox)row.FindControl("txtEndDt")).Text == ((TextBox)frmPvdrYr.Row.FindControl("txtEndDt")).Text)
{
((TextBox)frmPvdrYr.Row.FindControl("txtStartDt")).Text = string.Empty;
((TextBox)frmPvdrYr.Row.FindControl("txtEndDt")).Text = string.Empty;
ClientScript.RegisterStartupScript(this.GetType(), "DateError", "<script language='javascript'>alert('Please enter valid start and/or end date.');</script>");
return;
}
}
}
有人可以帮忙吗?我不知道还有什么可以尝试。