0

我试过这个 -

if (FormView1.CurrentMode == FormViewMode.ReadOnly)
{
 DropDownList ddlexpense = (DropDownList)FormView1.Row.FindControl("ddle");
}

在 FormView1 DataBound ,Init,ItemCreated 和单独的函数上,但我总是得到相同的错误 - System.NullReferenceException:对象引用未设置为对象的实例

4

1 回答 1

0
var cnt = FindControl(formViewTemplate.Row, "controlName");
            var htmlControl = cnt as HtmlControl;
            if (htmlControl != null)
            {//---------------------}
private Control FindControl(Control parent, string id)
    {
        foreach (Control child in parent.Controls)
        {
            string childId = string.Empty;
            if (child.ID != null)
            {
                childId = child.ID;
            }
            if (childId.ToLower() == id.ToLower())
            {
                return child;
            }
            if (child.HasControls())
            {
                Control response = FindControl(child, id);
                if (response != null)
                    return response;
            }
        }

        return null;
    }
于 2013-08-13T06:43:05.330 回答