Monday, January 28, 2019

Asp.net DropDownList, limit text shown in list separate from the controls width.

Hey, I am working on adding some features to a custom user control that essentially uses a textbox + a dropdown list to mimic the functionality of a forms combo box, so that when a user selects an item the text is placed in the text box so that it can be further edited before being saved in the database.

Here is the basic setup for the control

<asp:TextBox ID="CTText" TextMode="MultiLine" Width="80%" Height="60px" runat="server"></asp:TextBox> <asp:DropDownList ID="CTDDL" runat="server" Height="21" AutoPostBack="True" Width="20" OnSelectedIndexChanged="CTDDL_NewSelection" OnTextChanged="CTDDL_TextChanged"></asp:DropDownList> <asp:ImageButton ID="BtnAddPanel" runat="server" ImageAlign="Baseline" ImageUrl="~/_assets/img/plus.png" OnClick="BtnAddPanel_Click" /> 

The issue I am trying to figure out is how to limit the text displayed in the drop list itself, there are some very long options and I would like to only display a substring of the first 100 characters or so to differentiate between selectable values but keep the value itself as the full text so when selected the full text gets added to the textbox.

I have found examples of how to do this for a Gridview by setting the text properties to evaluate the value and get the substring, however for a dropdown list it appears it wont be just that easy.

Text='<%# Eval("Content").ToString().Length > 100? (Eval("Content") as string).Substring(0,100) + " ..." : Eval("Content") %>' >

trying to figure out if I can adapt this approach without hacking about with the list itself in the backend code.

thanks in advance!!

Asp.net DropDownList, limit text shown in list separate from the controls width. Click here
  • Blogger Comment
  • Facebook Comment

0 comments:

Post a Comment

The webdev Team