2013-08-05 100 views
0

我有一個dropdownlist,它有一個單一的元素開始,爲每一個單一的用戶。點擊展開DropDown List

元素的名稱是'Standard'。由於它是單個元素,因此單擊下拉列表不會向下擴展下拉列表。

有沒有什麼方法,這樣我可以擴大在點擊下拉列表,即使它在一個單一的元素。

我知道這個問題沒有多大意義,但我的客戶對這樣的事情感興趣。

任何變通,任何操作,任何種類的CSS會工作。

任何指針將不勝感激。是的,我的申請是在ASP.NET

代碼:

<div style="float: left; vertical-align: middle;"> 
<asp:DropDownList ID="dropDownListView" Width="100px" runat="server" CssClass="DropDownStyleSmallWidth"> 
</asp:DropDownList> 
&nbsp;</div> 

代碼背後:

public void PopulateOtherViews() 
    { 
     SaveReportViewFilter<ReportFilterBase> newObj = new SaveReportViewFilter<ReportFilterBase>(); 
     ViewColumnOptions vwobj = new ViewColumnOptions(); 
     newObj.UserName = vwobj.Page.User.Identity.Name; 
     SaveReportView<ReportFilterBase> obj2 = new SaveReportView<ReportFilterBase>(); 
     DataTable dt = obj2.GetSaveReportViewFromDataBase(newObj); 
     dropDownListView.DataSource = dt; 
     dropDownListView.DataTextField = dt.Columns[0].ToString(); 
     dropDownListView.DataValueField = dt.Columns[0].ToString(); 
     dropDownListView.DataBind(); 

    } 

基本上我的下拉列表是一個用戶控件,其中填充在Page_Load中。

+0

爲什麼DNT添加'的 - 選擇 -'現在點擊你會看到你的其他值,同時也發佈你的HTML標記,以方便讀者閱讀。 –

+0

我不允許使用Select or Choose kind listitem ...我的應用程序是這樣的標準是默認的每個人和人們可以通過點擊一些圖像按鈕,我已經提供了創建自己的元素..這些元素將被添加到下拉列表動態..因此,如果用戶創建他自己的元素,然後點擊下拉列表,它會展開。 – Anurag

回答

1

此代碼將擴大DropDownListBox

<script src="http://code.jquery.com/jquery-1.10.1.min.js"></script> 
<script src="http://code.jquery.com/jquery-migrate-1.2.1.min.js"></script> 
<script> 
    $(function() { 
     $('#Standard').click(function(){ 
     $(this).attr("size","1"); 
     }); 
    }); 
</script> 

希望這有助於。

+0

感謝buddy ..我會嘗試它,並會保持線程更新.. – Anurag

+0

嘿Mayank .. how does this code work..does it it that it will take the id of Standard element and on the click of it it would try擴大下拉列表...我需要添加一個onclick事件的下拉列表,我可以在上面的代碼段? – Anurag

+0

我編輯了我的答案...只需在'

0

在這裏,我添加了一個項目列表到我的下拉列表,並點擊它的擴展到向下作爲你要求的, 如果它的空白,它會向下擴展。

HTML標記:

<asp:DropDownList ID="DropDownList1" runat="server"> 
     <asp:ListItem>ABC</asp:ListItem> 
    </asp:DropDownList> 

截圖:

enter image description here


enter image description here

+0

HI Satinder,是的,我可以看到即使是一個空的dropdownlist在下面展開,但在我的情況下,我通過綁定下拉列表一個數據表從數據庫中取得值..我knw它沒有任何意義,但我仍然不能擴展ddl,當我只有一個值,即標準..任何意見?? – Anurag

+0

@Anurag:爲了更好理解,請發佈您的代碼,可能是他們的問題,同時填充下拉列表 –

+0

@ Satinder ..已編輯的問題和添加的代碼位...我的應用程序使用ASP.NET 2.0控件..我幫助那.. .. :) – Anurag