其他分享
首页 > 其他分享> > 如何访问Formview中的控件

如何访问Formview中的控件

作者:互联网

原文链接:http://www.cnblogs.com/JoeDZ/archive/2008/02/27/1083260.html None.gif//.net Framework类库中的FindControl方法可以帮助我们访问Formview中的控件:
None.gifprotected void FormView1_ItemCreated(object sender, EventArgs e)   
ExpandedBlockStart.gifContractedBlock.gifdot.gif{        
InBlock.gif    DropDownList test;        
InBlock.gif   switch (FormView1.CurrentMode)       
ExpandedSubBlockStart.gifContractedSubBlock.gif   dot.gif{            
InBlock.gif         case FormViewMode.Edit: 
InBlock.gif            test = ((DropDownList)FormView1.Row.FindControl("DropDownList3")); 
InBlock.gif            test.Attributes.Add("onchange", "FControl('" + test.UniqueID + "');");    
InBlock.gif            break; 
InBlock.gif       case FormViewMode.Insert: 
InBlock.gif               test = ((DropDownList)FormView1.Row.FindControl("DropDownList3"));  
InBlock.gif              test.Attributes.Add("onchange", "FControl('" + test.UniqueID + "');");   
InBlock.gif             break;  
ExpandedSubBlockEnd.gif      }   
ExpandedBlockEnd.gif}
None.gif
None.gif//上面的程序实现的功能是:
None.gif//给FormView中的EditItemTemplate和InsertItemTemplate中的DropDownList控件加上FControl;
None.gif//FControl方法的代码是:
None.gif  function FControl(ctlName)        
ExpandedBlockStart.gifContractedBlock.gifdot.gif
InBlock.gif           var rowIndex=document.getElementById(ctlName).selectedIndex;
InBlock.gif            if(document.getElementById(ctlName).options[rowIndex].innerText=='58')
ExpandedSubBlockStart.gifContractedSubBlock.gif            dot.gif{
InBlock.gif                document.getElementById('FControl').style.display="";
ExpandedSubBlockEnd.gif            }
InBlock.gif            else
ExpandedSubBlockStart.gifContractedSubBlock.gif            dot.gif{
InBlock.gif                document.getElementById('FControl').style.display="none"; 
ExpandedSubBlockEnd.gif           } 
ExpandedBlockEnd.gif}
None.gif//当DropDownList的值为58时显示id为FControl的组件,否则不显示。
None.gif

转载于:https://www.cnblogs.com/JoeDZ/archive/2008/02/27/1083260.html

标签:控件,document,FormView1,访问,getElementById,FControl,test,DropDownList,Formview
来源: https://blog.csdn.net/weixin_30609287/article/details/98605047