FormView里的定义:
这样的定义就是让用户从下拉列表里选择一个客户,如果选择了新客户,就要求输入新客户的名称
这里用到的CSS里定义的tableNotSelect是这样的:
这里就是要给这个DropDownlist控件在客户端加一个onchange事件,控制ClientNameTextBox是否显示,我使用JavaScript
<script language="javascript">
function showclient(s,textboxName)
{
var tbn;
tbn=document.getElementById(textboxName);
if(tbn!=null)
{
if(s==0)
{
eval(tbn).style.display="block";
eval(tbn).value="";
eval(tbn).focus();
}
else
{
eval(tbn).style.display="none";
}
}
}
</script>
然后呢,还要把DropDownlist控件和这个JS函数关连:
protected void fvReprot_DataBound(object sender, EventArgs e)
{
if (fvReprot.CurrentMode == FormViewMode.Edit)
{
setClientNameEnable("ddlClientNameList", "ClientNameTextBox");
}
else if (fvReprot.CurrentMode == FormViewMode.Insert)
{
setClientNameEnable("ddlClientNameList", "ClientNameTextBox");
}
}
private void setClientNameEnable(string ddlName, string tbName)
{
//加入事件
DropDownList myddl = new DropDownList();
TextBox mytb=new TextBox();
myddl = (DropDownList)fvReprot.FindControl(ddlName);
mytb=(TextBox)fvReprot.FindControl(tbName);
if (myddl != null && mytb!=null)
{
string action="";
action="showclient(this.value,'" + mytb.ClientID + "')";
myddl.Attributes.Add("onchange", action);
}
}