2015-11-17 39 views
1

我想檢查是否其他條件適用於asp.net C#代碼後面什麼都沒有得到是下拉更改有條件如果選定的索引值爲零,然後ALERT 0警報但沒有顯示任何選定的索引選擇不知道我在哪裏出錯。關於更改顯示警報C#asp.net

CS:代碼背後

protected void Student_type_dd_change(object sender, EventArgs e) 
     { 

      if (Student_type_dd.SelectedIndex == 0) 
      { 
       Response.Write("<script>alert('0');</script>"); 
      } 
      else if (Student_type_dd.SelectedIndex == 1) 
      { 
       Response.Write("<script>alert('1');</script>"); 
      } 
      else if (Student_type_dd.SelectedIndex == 2) 
      { 
       Response.Write("<script>alert('2');</script>"); 
      } 

     } 

.aspx的

<asp:DropDownList ID="Student_type_dd" runat="server" onselectedindexchanged="Student_type_dd_change" autopostback="true" > 
        <asp:ListItem Text="Select Type" Value="0" /> 
         <asp:ListItem Text="All Students" Value="All Students" /> 
         <asp:ListItem Text="Class Wise" Value="Class Wise" /> 
         <asp:ListItem Text="Select Specific" Value="Select Specific" /> 
       </asp:DropDownList> 
+2

你爲什麼不使用調試器,而不是使用JavaScript來輸出什麼? –

+0

@StephenBrickner不會'Response.Write'將它寫入回傳的內容? – Rawling

+0

考慮到這個問題的描述和我們在這裏看到的代碼,我懷疑你很可能***將'DropDownList'值(並因此選擇了索引)覆蓋在' Page_Load'。正如其他人所暗示的,這對於「調試」你的代碼來說也是一種糟糕的方式。使用Visual Studio附帶的實際調試器。 – David

回答

2

您可以使用這樣的事情:

ScriptManager.RegisterStartupScript(this, typeof(Page), "alert", "alert('0')", true); 
+0

如果你不介意,我可以問你一個簡單的問題嗎?和上面的工作表示感謝 – Shaik

+1

@Shaik:Stack Overflow是一個問答網站。你不必要求允許提出問題。本網站的全部目的是提出問題並回答問題。 – David

+0

當然,如果我不能回答,也許別人會。 –