在asp。net里面,页面上面我想根据一个dropdownlist控件的选择项,来显示不同的html片断。
<% if( lstAlterItem.SelectedValue=="0") %><p align="center">一、合同变更<BR>
...........................
<% else %><p align="center">二、费用变更</p>
...................这样提示<% else %>处:  CS1525: 无效的表达式项“else”
但是如果简单点,就没有问题:<% if( lstAlterItem.SelectedValue=="0") %>
aa
<% else %>
bb
为什么啊?

解决方案 »

  1.   

    <% if( lstAlterItem.SelectedValue=="0") %><p align="center">一、合同变更<BR>
    ...........................
    <% else %><p align="center">二、费用变更</p>
    你这样写,SCRIPT语句就段开了啊,所以它不能识别else.
    <% if( lstAlterItem.SelectedValue=="0") %>
    aa
    <% else %>
    bb
    这样写就能识别啊,什么aa,bb都归成SCRIPT语句里面了。
      

  2.   

    <% if( lstAlterItem.SelectedValue=="0") %><p align="center">一、合同变更<BR>
    ...........................
    <% else %><p align="center">二、费用变更</p>
    ...................改为:<% if( lstAlterItem.SelectedValue=="0") {%><p align="center">一、合同变更<BR>
    ...........................
    <%} else {%><p align="center">二、费用变更</p>
    ...................
      

  3.   

    干嘛不用 <SELECT NAME="select1"></SELECT> 这样完全在客户端完成,不需要刷新.
      

  4.   

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
    <HTML>
    <HEAD>
    <TITLE> display:none/block visibility:hidden/visible</TITLE>
    <META NAME="Generator" CONTENT="EditPlus">
    <META NAME="Author" CONTENT="">
    <META NAME="Keywords" CONTENT="">
    <META NAME="Description" CONTENT="">
    </HEAD><BODY><SELECT NAME="select1" id="select1" onchange="doChange()">
    <option value="1">1</option>
    <option value="2">2</option>
    <option value="3">3</option>
    </SELECT>
    <div id ="div1" style ="display:none"><p align="center">一、合同变更<BR></div> 
    <div id ="div2" style ="display:none"><p align="center">二、费用变更</p></div>
    <div id ="div3" style ="display:none"><p align="center">三、其它变更</p></div>
    <script>
    function doChange()
    {
    var sel = select1.options[select1.selectedIndex].value
    if (sel == "1")
    {
    div1.style.display = "block";
    div2.style.display = "none";
    div3.style.display = "none";
    }
    else if (sel =="2")
    {
    div1.style.display = "none";
    div2.style.display = "block";
    div3.style.display = "none";
    }
    else
    {
    div1.style.display = "none";
    div2.style.display = "none";
    div3.style.display = "block";
    }
    }
    doChange();
    </script>
    </BODY>
    </HTML>