listview 中加入DropdownList,再根据DropDownList选择内容判断是否隐藏相应控件,用JQ怎么做(不能在客户端每点一次都要传回服务器,太浪费资源),我做了后显示和隐藏控件是可以了,但是不能“更新”“取消”和插入新内容了
代码如下:
protected void ListView1_ItemCreated(object sender, ListViewItemEventArgs e)
{
if (e.Item.ItemType == ListViewItemType.DataItem || e.Item.ItemType == ListViewItemType.InsertItem)
{
DropDownList ddlLinkType = (DropDownList)e.Item.FindControl("ddlLinkType");
TextBox LogoUrlTextBox = (TextBox)e.Item.FindControl("LogoUrlTextBox");
if (ddlLinkType.SelectedValue == "Text" && LogoUrlTextBox != null)
{
LogoUrlTextBox.Style["display"] = "none";
}
if (ddlLinkType != null && LogoUrlTextBox != null) //这条语句加上就不能更新、取消和插入。否则就是好用的。这条语句的实现的功能是当在下拉列表框中选择文本时把“LogoUrlTextBox”控件隐藏,以便不让用户输入信息
{
ddlLinkType.Attributes["onchange"] = "onLinkTypeChange(this,'" + LogoUrlTextBox.ClientID + "')";
}
}
}
onLinkTypeChange函数如下:
<script type="text/javascript">
function onLinkTypeChange(src, logoUrlTextBox) {
if ($(src).val() == "Text") {
$("#" + logoUrlTextBox).hide();
}
else {
$("#" + logoUrlTextBox).show();
}
}
</script>