It is possible to make Dropdownlist "readonly" equal to Textfield

Asked

Viewed 125 times

-3

I understand that the DropDownList already is readonly, since I can not change the values of the options, however I need to maintain the uniform behavior of the screen.

In query mode I can assign a readonly at the TextBox and the text is selectable (double click) but unchangeable. I want to allow the user to also select the text of the DropDownList, so I can’t assign disabled to the countryside.

@Html.DropDownListFor(m => m.MeuValor, Model.MinhaLista, width: 100, renderContainer: false, showDisplayName: false, tipoUnidadeHtml: TipoUnidadeHtml.Porcentagem)

this is my code. I cannot add the (object)new { @disabled = "disabled" }) because then the double click does not work.

  • But do you have to put a dropdown on the visuals? I suppose you’re creating a page visualizing the content that was edited, if so, you could simply put the value.

  • Your question is very confused. It seems to me a film that I start to watch in half and I don’t see until the end. Of what DropDownList Are you talking? Where’s your code?

  • @Html.DropDownListFor(m => m.MeuValor, Model.MinhaLista, width: 100, renderContainer: false, showDisplayName: false, tipoUnidadeHtml: TipoUnidadeHtml.Porcentagem) this is my code.. I cannot add the (object)new { @disabled = "disabled" }) because there the double click doesn’t work.

  • Edit the question by placing the code there, otherwise it gets a little hard to understand.

1 answer

3

I think what you want is not possible.

Going back a bit to the comment that I had already made why not simply show the value that the client selected? Add a field in model that returns to the View with the value of dropdown instead of key.

@Html.ValueFor(m => m.MeuValorString)

and if you need to submit the form, and not lose this value. Add Key in a hiddenfor

@Html.HiddenFor(m => m.MeuValor)
  • I haven’t found a solution to this point, I’ve done a lot of research and so far it’s impossible. To get around I will have to do this even you suggested (display the value in the query and the dropdown in the edition) but is not yet ideal.

  • I suggest something else, you foreach your list to print a table, and in the class of the Row you check if the value corresponds to the selected and you paint that Row of another color

  • I appreciate the suggestion but I can’t do this because the user wants to select the value (double-clicking the field) to copy. I had to create a TextBoxFor and control when to display one or the other.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.