IDictionary к SelectList?

@Meh для u ..

txtlist.setFilters(new InputFilter[] { new DigitsKeyListener( Boolean.FALSE,Boolean.TRUE) {

        int beforeDecimal = 7;
        int afterDecimal = 2;

        @Override
        public CharSequence filter(CharSequence source, int start, int end,Spanned dest, int dstart, int dend) {

            String etText = txtlist.getText().toString();
            String temp = txtlist.getText() + source.toString();
            if (temp.equals(".")) {
                return "0.";
            } else if (temp.toString().indexOf(".") == -1) {
                // no decimal point placed yet
                 if (temp.length() > beforeDecimal) {
                    return "";
                }
            } else {
                int dotPosition ;
                int cursorPositon = txtlistprice.getSelectionStart();
                if (etText.indexOf(".") == -1) {
                    dotPosition = temp.indexOf(".");
                }else{
                    dotPosition = etText.indexOf(".");
                }
                if(cursorPositon <= dotPosition){
                    String beforeDot = etText.substring(0, dotPosition);
                    if(beforeDot.length()<beforeDecimal){
                        return source;
                    }else{
                        if(source.toString().equalsIgnoreCase(".")){
                            return source;
                        }else{
                            return "";
                        }
                    }
                }else{
                    temp = temp.substring(temp.indexOf(".") + 1);
                    if (temp.length() > afterDecimal) {
                        return "";
                    }
                }
            }
            return super.filter(source, start, end, dest, dstart, dend);
        }
    } });
26
задан Andrew Hare 12 May 2009 в 02:20
поделиться

2 ответа

Просто установите "Value" и "Key" для dataValueField и dataTextField. Вы можете сделать это либо в самом View, либо в своих действиях (код ниже не тестировался).

var targets = new Dictionary<string, string>();
targets.Add("Key", "Value");

ViewData["MyList"] = new SelectList(targets, "Key", "Value");
42
ответ дан Peter Gluck 25 September 2019 в 07:21
поделиться

Ну, IDictionary наследуется от IEnumerable , поэтому вы должны иметь возможность передать этот словарь в один из конструкторов для SelectList .

2
ответ дан 28 November 2019 в 07:18
поделиться
Другие вопросы по тегам:

Похожие вопросы: