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 != null&&LogoURLTextBox != null)
{
ddlLinkType.Attributes["onchange"] = "onLinkTypeChange(this,'" + LogoURLTextBox.ClientID + "')";
}}}
JQuery的代码
<script src="js/jquery-1.4.2.js" type="text/javascript"></script>
<script type="text/javascript">
function onLinkTypeChange(src, logoTextId) {
if ($(src).val() == "Text") {
$("#" + logoTextId).hide();
}
else {
$("#" + logoTextId).show();
}
}
</script>
浏览器运行后的源文件
<select name="ListView1$ctrl2$ddlLinkType" id="ListView1_ddlLinkType" onchange="onLinkTypeChange(this,'ctrl2_LogoURLTextBox')">
<option value="Text">文本</option>
<option value="Picture">图片</option>
</select>
</td>
<td>
<input name="ListView1$ctrl2$SiteURLTextBox" type="text" maxlength="100" id="ListView1_SiteURLTextBox" />
<span id="ListView1_RequiredFieldValidator6" style="visibility:hidden;">*</span>
</td>
<td>
<input name="ListView1$ctrl2$LogoURLTextBox" type="text" id="ListView1_LogoURLTextBox" />
从上面明显看出 onchange找到的id出现错误,明显‘’单引号没有被输出???谁遇到这种情况,帮帮忙解决下。。。。谢谢
|