2014-12-24 68 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