如何访问Formview中的控件
作者:互联网
原文链接:http://www.cnblogs.com/JoeDZ/archive/2008/02/27/1083260.html
//.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的组件,否则不显示。
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的组件,否则不显示。
转载于: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