2016-04-11 62 views
1

我無法編輯(它被突出顯示爲棕色)下拉列表控件「頂部」字段在源代碼視圖,在asp.net中,使用Visual Studio時:爲什麼我不能在ASP.net中編輯dropdownlist的位置?

我可以編輯它下面的圖像控制!

 <asp:DropDownList ID="DropDownList1" runat="server" 
      DataSourceID="SqlDataSource1" DataTextField="AccountIdent" 
      DataValueField="AccountIdent"   
      style="top: 102px; left: 0px; position: absolute; height: 24px; width: 114px; z-index: 1;"> 
     </asp:DropDownList> 

     <asp:Image ID="Image3" runat="server"    
     style="top: 0px; left: 0px; position: absolute; height: 23px; width: 47px" /> 

這是爲什麼?

回答

1

我認爲這是因爲asp:Image會生成一個標籤<img/>而下拉列表會生成更多的標籤。

您應該使用CssClasses,如果你不想把它在另一個文件,你可以在頁面中使用它(它總是一個好主意,以保持在其他文件中的CSS),如:

<style type="text/css"> 
    .drop{ 
    top: 102px; left: 0px; position: absolute; height: 24px; width: 114px; z-index: 1; 
    } 
    .image{ 
    top: 0px; left: 0px; position: absolute; height: 23px; width: 47px 
    } 
</style> 

<asp:DropDownList ID="DropDownList1" runat="server" 
       DataSourceID="SqlDataSource1" DataTextField="AccountIdent" 
       DataValueField="AccountIdent" CssClass="drop"> 
      </asp:DropDownList> 

      <asp:Image ID="Image3" runat="server" CssClass="image"/> 
1

DropdownList沒有Style屬性,這就是爲什麼你不能設置it.For解決方案創建一個CSS類的屬性和設置的dropdownListcssClass的那類

<style> 
    .anyname { 
     top: 102px; left: 0px; position: absolute; height: 24px; width: 114px; z-index: 1; 
    } 
</style> 

並在下拉 設置

<asp:DropDownList ID="DropDownList1" runat="server" 
      DataSourceID="SqlDataSource1" DataTextField="AccountIdent" 
      DataValueField="AccountIdent" CssClass="anyname">   
     </asp:DropDownList> 
+0

但我發佈的代碼是自動生成的VS,當我拖放設計模式的下拉列表控制!爲什麼VS會這樣做,如果它不正確?! – ManInMoon

+0

我不知道,也許我是正確的人回答這個問題,因爲這個問題可能有很多答案,也許它的錯誤或可能是某種控制相關的問題..我發現這個鏈接也許這對你有幫助https:/ /blogs.msdn.microsoft.com/webdev/2008/03/11/absolute-and-relative-positioning-in-visual-web-developer-2008-designer/ – KanisXXX

相關問題