DropDownList下拉框可編輯功能的簡單實現

來源:互聯網
上載者:User
BingWay原創作品,轉載請註明作者和出處。

在Web編程中,可編輯的下拉式清單一直是個不是問題的問題,隨之而出的第三方控制項、Js控制Select控制項的代碼也隨處可見,但是能相容所有瀏覽器,

下拉框和文字框緊密結合,實現起來卻不是那麼容易。最近做項目,想到一個DropDownList可編輯控制項比較好的實現方法,和大家分享一下。

我的方法是在DropDownList上加層和文字框,有人喜歡用像素定位文字框,這樣做不但很難定位,而且瀏覽器運行出來的效果可能有偏差;用層定位相對而言比較好控制。Code
 1  <asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="true" 
 2 OnSelectedIndexChanged="DropDownList1_SelectedIndexChanged"
 3             Width="180px"  style="position:absolute; ">
 4             <asp:ListItem>測試一</asp:ListItem>
 5             <asp:ListItem>測試二</asp:ListItem>
 6             <asp:ListItem>測試三</asp:ListItem>
 7         </asp:DropDownList>
 8          <div>
 9          <iframe id="DivShims" src="javascript:false;" scrolling="no" 
10 frameborder="0" style="position: absolute; height: 20px;" width="158px">
11          </iframe>
12          <input type="text" id="txtCName" runat="server" style="width: 158px; position:absolute;" />
13          </div>

下拉框和文字框緊密整合。

  頁面載入及觸發DropDownList1_SelectedIndexChanged事件,給文字框賦值。  string text = DropDownList1.SelectedValue.ToString();//DropDownList1選中的值

  txtCName.Value = text;//給txtCName賦值  運行測試。  更改下拉框的值。這是我想到的最簡單的方法,園子裡的朋友,有什麼更好的方法,請不吝賜教。

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.