2014-12-24 102 views
-1

軟件:的Visual Web Developer 2008 Express版本下拉不對齊文本

書:編程ASP.NET 3.5,由O'Reilly

這是代碼從書中

<form id="form1" runat="server"> 
    <div> 
     <p> 
      <asp:ScriptManager ID="ScriptManager1" runat="server"> 
      </asp:ScriptManager> 
      <asp:Image ID="img1" runat="server" 
       AlternateText="Popfly Duck" ImageUrl="Images/ducky.jpg" /> 
      This is a sample paragraph which is being used to demonstrate 
      the effects of various values of ImageAlign. As you will see, 
      the effects are sometimes difficult to pin down, and vary 
      depending on the width of the browser window. 
     </p> 
     <hr /> 
     <asp:Button ID="Button1" runat="server" Text="Sample Button" /> 
     <asp:Image ID="img2" runat="server" 
      AlternateText="Popfly Duck" ImageUrl="Images/ducky.jpg" /> 
     <hr /> 
     <asp:DropDownList ID="ddlAlign" runat="server" AutoPostBack="True"> 
      <asp:ListItem Text="NotSet" /> 
      <asp:ListItem Text="AbsBottom" /> 
      <asp:ListItem Text="AbsBiddle" /> 
      <asp:ListItem Text="Top" /> 
      <asp:ListItem Text="Bottom" /> 
      <asp:ListItem Text="BaseLine" /> 
      <asp:ListItem Text="TextTop" /> 
      <asp:ListItem Text="Left" /> 
      <asp:ListItem Text="Right" /> 
     </asp:DropDownList> 
    </div> 
    </form> 

這裏是由此產生的網頁

enter image description here

但是這本書沒有給出頁面後面的代碼,即aspx.cs,所以我試圖確定正確的代碼,因此當用戶從下拉列表中選擇時,文本將相應地對齊。當我嘗試

protected void ddlAlign_SelectedIndexChanged(object sender, EventArgs e) 
{ 
    img1.ImageAlign = ddlAlign.Text; 
} 

我得到ddlAlign.Text下的紅色波浪線。幫幫我!

+0

您是否在選擇下拉菜單後檢查網頁瀏覽器中的HTML源代碼?如果是的話你看到了img標籤? –

+1

@Glowie請檢查答案並接受正確的答案,或者發表評論,與他人分享經驗。 – QMaster

+0

@QMaster ---星期一我回到辦公室時,我會檢查答案並選擇正確答案---聖誕快樂! – Glowie

回答

1

ImageAlignenum。你不能用string來指定它,所以你必須先解析它。 Enum.Parse可以爲您做到這一點:

img1.ImageAlign = (ImageAlign)Enum.Parse(typeof(ImageAlign), ddlAlign.Text); 
+0

星期一我回到辦公室時我會試試這個---聖誕快樂! – Glowie