如何访问Formview中的控件

.net Framework类库中的FindControl方法可以帮助我们访问Formview中的控件:
protected void FormView1_ItemCreated(object sender, EventArgs e)   
{       
    DropDownList test;       
   switch (FormView1.CurrentMode)       
   {           
         case FormViewMode.Edit: 
            test = ((DropDownList)FormView1.Row.FindControl("DropDownList3")); 
            test.Attributes.Add("onchange", "FControl('" + test.UniqueID + "');");    
            break; 
       case FormViewMode.Insert: 
               test = ((DropDownList)FormView1.Row.FindControl("DropDownList3"));  
              test.Attributes.Add("onchange", "FControl('" + test.UniqueID + "');");   
             break;  
      }   
}

  上面的程序实现的功能是:
给FormView中的EditItemTemplate和InsertItemTemplate中的DropDownList控件加上FControl;
FControl方法的代码是:
  function FControl(ctlName)       

           var rowIndex=document.getElementById(ctlName).selectedIndex;
            if(document.getElementById(ctlName).options[rowIndex].innerText=='58')
            {
                document.getElementById('FControl').style.display="";
            }
            else
            {
                document.getElementById('FControl').style.display="none"; 
           } 
       }
当DropDownList的值为58时显示id为FControl的组件,否则不显示。

posted on 2008-04-02 16:34  秋天  阅读(1588)  评论(0编辑  收藏  举报

导航