• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

C# SelectList类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C#中SelectList的典型用法代码示例。如果您正苦于以下问题:C# SelectList类的具体用法?C# SelectList怎么用?C# SelectList使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



SelectList类属于命名空间,在下文中一共展示了SelectList类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。

示例1: Constructor3SetsProperties_Value_Text

        public void Constructor3SetsProperties_Value_Text()
        {
            // Arrange
            IEnumerable items = new object[0];

            // Act
            SelectList selectList = new SelectList(items, "SomeValueField", "SomeTextField");

            // Assert
            Assert.Same(items, selectList.Items);
            Assert.Equal("SomeValueField", selectList.DataValueField);
            Assert.Equal("SomeTextField", selectList.DataTextField);
            Assert.Null(selectList.SelectedValues);
            Assert.Null(selectList.SelectedValue);
        }
开发者ID:ahmetgoktas,项目名称:aspnetwebstack,代码行数:15,代码来源:SelectListTest.cs


示例2: Constructor_SetsProperties_Items_Value_Text_SelectedValue_DisabledValues_Group

        public void Constructor_SetsProperties_Items_Value_Text_SelectedValue_DisabledValues_Group()
        {
            // Arrange
            IEnumerable items = new[]
            {
                new { Value = "A", Text = "Alice", Group = "AB" },
                new { Value = "B", Text = "Bravo", Group = "AB" },
                new { Value = "C", Text = "Charlie", Group = "C" },
            };
            object selectedValue = "A";
            IEnumerable disabledValues = new[] { "A", "C" };

            // Act
            SelectList selectList = new SelectList(items,
                "Value",
                "Text",
                "Group",
                selectedValue,
                disabledValues);
            List<object> selectedValues = selectList.SelectedValues.Cast<object>().ToList();

            // Assert
            Assert.Same(items, selectList.Items);
            Assert.Equal("Value", selectList.DataValueField);
            Assert.Equal("Text", selectList.DataTextField);
            Assert.Same(selectedValue, selectList.SelectedValue);
            Assert.Single(selectedValues);
            Assert.Same(selectedValue, selectedValues[0]);
            Assert.Equal("Group", selectList.DataGroupField);
            Assert.Same(disabledValues, selectList.DisabledValues);
        }
开发者ID:ahmetgoktas,项目名称:aspnetwebstack,代码行数:31,代码来源:SelectListTest.cs


示例3: GetViewDataWithSelectList

 private static ViewDataDictionary GetViewDataWithSelectList()
 {
     ViewDataDictionary viewData = new ViewDataDictionary();
     SelectList selectList = new SelectList(MultiSelectListTest.GetSampleAnonymousObjects(), "Letter", "FullWord", "C");
     viewData["foo"] = selectList;
     viewData["foo.bar"] = selectList;
     return viewData;
 }
开发者ID:AndreGleichner,项目名称:aspnetwebstack,代码行数:8,代码来源:SelectExtensionsTest.cs


示例4: Constructor3SetsProperties_SelectedValue_DisabledValues

        public void Constructor3SetsProperties_SelectedValue_DisabledValues()
        {
            // Arrange
            IEnumerable items = new[] { "A", "B", "C" };
            IEnumerable selectedValues = "A";
            IEnumerable disabledValues = new[] { "B", "C" };

            // Act
            SelectList multiSelect = new SelectList(items, selectedValues, disabledValues);

            // Assert
            Assert.Same(items, multiSelect.Items);
            Assert.Equal(new object[] { selectedValues }, multiSelect.SelectedValues);
            Assert.Equal(disabledValues, multiSelect.DisabledValues);
            Assert.Null(multiSelect.DataTextField);
            Assert.Null(multiSelect.DataValueField);
        }
开发者ID:ahmetgoktas,项目名称:aspnetwebstack,代码行数:17,代码来源:SelectListTest.cs


示例5: DropDownListUsesExplicitValueIfNotProvidedInViewData

        public void DropDownListUsesExplicitValueIfNotProvidedInViewData()
        {
            // Arrange
            HtmlHelper helper = MvcHelper.GetHtmlHelper(new ViewDataDictionary());
            SelectList selectList = new SelectList(MultiSelectListTest.GetSampleAnonymousObjects(), "Letter", "FullWord", "C");

            // Act
            MvcHtmlString html = helper.DropDownList("foo", selectList, (string)null /* optionLabel */);

            // Assert
            Assert.Equal(
                "<select id=\"foo\" name=\"foo\"><option value=\"A\">Alpha</option>" + Environment.NewLine
              + "<option value=\"B\">Bravo</option>" + Environment.NewLine
              + "<option selected=\"selected\" value=\"C\">Charlie</option>" + Environment.NewLine
              + "</select>",
                html.ToHtmlString());
        }
开发者ID:marojeri,项目名称:aspnetwebstack,代码行数:17,代码来源:SelectExtensionsTest.cs


示例6: DropDownListUsesViewDataDefaultValue

        public void DropDownListUsesViewDataDefaultValue()
        {
            // Arrange
            HtmlHelper helper = MvcHelper.GetHtmlHelper(_dropDownListViewData);
            SelectList selectList = new SelectList(MultiSelectListTest.GetSampleStrings(), "Charlie");

            // Act
            MvcHtmlString html = helper.DropDownList("foo", selectList, (string)null /* optionLabel */);

            // Assert
            Assert.Equal(
                "<select id=\"foo\" name=\"foo\"><option>Alpha</option>" + Environment.NewLine
              + "<option selected=\"selected\">Bravo</option>" + Environment.NewLine
              + "<option>Charlie</option>" + Environment.NewLine
              + "</select>",
                html.ToHtmlString());
        }
开发者ID:marojeri,项目名称:aspnetwebstack,代码行数:17,代码来源:SelectExtensionsTest.cs


示例7: Constructor2SetsProperties_Items_SelectedValue

        public void Constructor2SetsProperties_Items_SelectedValue()
        {
            // Arrange
            IEnumerable items = new object[0];
            object selectedValue = new object();

            // Act
            SelectList selectList = new SelectList(items, selectedValue);
            List<object> selectedValues = selectList.SelectedValues.Cast<object>().ToList();

            // Assert
            Assert.Same(items, selectList.Items);
            Assert.Null(selectList.DataValueField);
            Assert.Null(selectList.DataTextField);
            Assert.Same(selectedValue, selectList.SelectedValue);
            Assert.Single(selectedValues);
            Assert.Same(selectedValue, selectedValues[0]);
        }
开发者ID:ahmetgoktas,项目名称:aspnetwebstack,代码行数:18,代码来源:SelectListTest.cs


示例8: DropDownListUsesExplicitValueIfNotProvidedInViewData_Unobtrusive

        public void DropDownListUsesExplicitValueIfNotProvidedInViewData_Unobtrusive()
        {
            // Arrange
            HtmlHelper helper = MvcHelper.GetHtmlHelper(new ViewDataDictionary());
            helper.ViewContext.ClientValidationEnabled = true;
            helper.ViewContext.UnobtrusiveJavaScriptEnabled = true;
            helper.ViewContext.FormContext = new FormContext();
            helper.ClientValidationRuleFactory = (name, metadata) => new[] { new ModelClientValidationRule { ValidationType = "type", ErrorMessage = "error" } };
            SelectList selectList = new SelectList(MultiSelectListTest.GetSampleAnonymousObjects(), "Letter", "FullWord", "C");

            // Act
            MvcHtmlString html = helper.DropDownList("foo", selectList, (string)null /* optionLabel */);

            // Assert
            Assert.Equal(
                "<select data-val=\"true\" data-val-type=\"error\" id=\"foo\" name=\"foo\"><option value=\"A\">Alpha</option>" + Environment.NewLine
              + "<option value=\"B\">Bravo</option>" + Environment.NewLine
              + "<option selected=\"selected\" value=\"C\">Charlie</option>" + Environment.NewLine
              + "</select>",
                html.ToHtmlString());
        }
开发者ID:marojeri,项目名称:aspnetwebstack,代码行数:21,代码来源:SelectExtensionsTest.cs


示例9: DropDownListWithObjectDictionaryWithUnderscoresAndSelectListNoOptionLabel

        public void DropDownListWithObjectDictionaryWithUnderscoresAndSelectListNoOptionLabel()
        {
            // Arrange
            HtmlHelper helper = MvcHelper.GetHtmlHelper(new ViewDataDictionary());
            SelectList selectList = new SelectList(MultiSelectListTest.GetSampleStrings());

            // Act
            MvcHtmlString html = helper.DropDownList("foo", selectList, HtmlHelperTest.AttributesObjectUnderscoresDictionary);

            // Assert
            Assert.Equal(
                "<select foo-baz=\"BazObjValue\" id=\"foo\" name=\"foo\"><option>Alpha</option>" + Environment.NewLine
              + "<option>Bravo</option>" + Environment.NewLine
              + "<option>Charlie</option>" + Environment.NewLine
              + "</select>",
                html.ToHtmlString());
        }
开发者ID:AndreGleichner,项目名称:aspnetwebstack,代码行数:17,代码来源:SelectExtensionsTest.cs


示例10: SelectHelpersUseCurrentCultureToConvertValues

        public void SelectHelpersUseCurrentCultureToConvertValues()
        {
            // Arrange
            HtmlHelper defaultValueHelper = MvcHelper.GetHtmlHelper(new ViewDataDictionary
            {
                { "foo", new[] { new DateTime(1900, 1, 1, 0, 0, 1) } },
                { "bar", new DateTime(1900, 1, 1, 0, 0, 1) }
            });
            HtmlHelper helper = MvcHelper.GetHtmlHelper();
            SelectList selectList = new SelectList(GetSampleCultureAnonymousObjects(), "Date", "FullWord", new DateTime(1900, 1, 1, 0, 0, 0));

            var tests = new[]
            {
                // DropDownList(name, selectList, optionLabel)
                new
                {
                    Html = "<select id=\"foo\" name=\"foo\"><option selected=\"selected\" value=\"01/01/1900 00:00:00\">Alpha</option>" + Environment.NewLine
                         + "<option value=\"01/01/1900 00:00:01\">Bravo</option>" + Environment.NewLine
                         + "<option value=\"01/01/1900 00:00:02\">Charlie</option>" + Environment.NewLine
                         + "</select>",
                    Action = new Func<MvcHtmlString>(() => helper.DropDownList("foo", selectList, (string)null))
                },
                // DropDownList(name, selectList, optionLabel) (With default value selected from ViewData)
                new
                {
                    Html = "<select id=\"bar\" name=\"bar\"><option value=\"01/01/1900 00:00:00\">Alpha</option>" + Environment.NewLine
                         + "<option selected=\"selected\" value=\"01/01/1900 00:00:01\">Bravo</option>" + Environment.NewLine
                         + "<option value=\"01/01/1900 00:00:02\">Charlie</option>" + Environment.NewLine
                         + "</select>",
                    Action = new Func<MvcHtmlString>(() => defaultValueHelper.DropDownList("bar", selectList, (string)null))
                },
                // ListBox(name, selectList)
                new
                {
                    Html = "<select id=\"foo\" multiple=\"multiple\" name=\"foo\"><option selected=\"selected\" value=\"01/01/1900 00:00:00\">Alpha</option>" + Environment.NewLine
                         + "<option value=\"01/01/1900 00:00:01\">Bravo</option>" + Environment.NewLine
                         + "<option value=\"01/01/1900 00:00:02\">Charlie</option>" + Environment.NewLine
                         + "</select>",
                    Action = new Func<MvcHtmlString>(() => helper.ListBox("foo", selectList))
                },
                // ListBox(name, selectList) (With default value selected from ViewData)
                new
                {
                    Html = "<select id=\"foo\" multiple=\"multiple\" name=\"foo\"><option value=\"01/01/1900 00:00:00\">Alpha</option>" + Environment.NewLine
                         + "<option selected=\"selected\" value=\"01/01/1900 00:00:01\">Bravo</option>" + Environment.NewLine
                         + "<option value=\"01/01/1900 00:00:02\">Charlie</option>" + Environment.NewLine
                         + "</select>",
                    Action = new Func<MvcHtmlString>(() => defaultValueHelper.ListBox("foo", selectList))
                }
            };

            // Act && Assert
            foreach (var test in tests)
            {
                Assert.Equal(test.Html, test.Action().ToHtmlString());
            }
        }
开发者ID:AndreGleichner,项目名称:aspnetwebstack,代码行数:57,代码来源:SelectExtensionsTest.cs


示例11: DropDownListWithErrorsAndCustomClass

        public void DropDownListWithErrorsAndCustomClass()
        {
            // Arrange
            SelectList selectList = new SelectList(MultiSelectListTest.GetSampleStrings());
            ViewDataDictionary viewData = GetViewDataWithErrors();
            HtmlHelper helper = MvcHelper.GetHtmlHelper(viewData);

            // Act
            MvcHtmlString html = helper.DropDownList("foo", selectList, null /* optionLabel */, new { @class = "foo-class" });

            // Assert
            Assert.Equal(
                "<select class=\"input-validation-error foo-class\" id=\"foo\" name=\"foo\"><option>Alpha</option>" + Environment.NewLine
              + "<option selected=\"selected\">Bravo</option>" + Environment.NewLine
              + "<option>Charlie</option>" + Environment.NewLine
              + "</select>",
                html.ToHtmlString());
        }
开发者ID:AndreGleichner,项目名称:aspnetwebstack,代码行数:18,代码来源:SelectExtensionsTest.cs


示例12: ListBoxForUsesLambdaDefaultValue

        public void ListBoxForUsesLambdaDefaultValue()
        {
            // Arrange
            FooArrayModel model = new FooArrayModel { foo = new[] { "Bravo" } };
            HtmlHelper<FooArrayModel> helper = MvcHelper.GetHtmlHelper(new ViewDataDictionary<FooArrayModel>(model));
            SelectList selectList = new SelectList(MultiSelectListTest.GetSampleStrings());

            // Act
            MvcHtmlString html = helper.ListBoxFor(m => m.foo, selectList);

            // Assert
            Assert.Equal(
                "<select id=\"foo\" multiple=\"multiple\" name=\"foo\"><option>Alpha</option>" + Environment.NewLine
              + "<option selected=\"selected\">Bravo</option>" + Environment.NewLine
              + "<option>Charlie</option>" + Environment.NewLine
              + "</select>",
                html.ToHtmlString());
        }
开发者ID:AndreGleichner,项目名称:aspnetwebstack,代码行数:18,代码来源:SelectExtensionsTest.cs


示例13: DropDownListUsesViewDataDefaultValueNoOptionLabel

        public void DropDownListUsesViewDataDefaultValueNoOptionLabel()
        {
            // Arrange
            HtmlHelper helper = MvcHelper.GetHtmlHelper(_dropDownListViewData);
            SelectList selectList = new SelectList(MultiSelectListTest.GetSampleStrings(), "Charlie");

            // Act
            MvcHtmlString html = helper.DropDownList("foo", selectList);

            // Assert
            Assert.Equal(
                @"<select id=""foo"" name=""foo""><option>Alpha</option>
<option selected=""selected"">Bravo</option>
<option>Charlie</option>
</select>",
                html.ToHtmlString());
        }
开发者ID:reza899,项目名称:aspnetwebstack,代码行数:17,代码来源:SelectExtensionsTest.cs


示例14: DropDownListForWithPrefixAndEmptyName

        public void DropDownListForWithPrefixAndEmptyName()
        {
            // Arrange
            HtmlHelper<FooModel> helper = MvcHelper.GetHtmlHelper(new ViewDataDictionary<FooModel>());
            SelectList selectList = new SelectList(MultiSelectListTest.GetSampleStrings());
            helper.ViewContext.ViewData.TemplateInfo.HtmlFieldPrefix = "MyPrefix";

            // Act
            MvcHtmlString html = helper.DropDownListFor(m => m, selectList, HtmlHelperTest.AttributesObjectDictionary);

            // Assert
            Assert.Equal(
                @"<select baz=""BazObjValue"" id=""MyPrefix"" name=""MyPrefix""><option>Alpha</option>
<option>Bravo</option>
<option>Charlie</option>
</select>",
                html.ToHtmlString());
        }
开发者ID:reza899,项目名称:aspnetwebstack,代码行数:18,代码来源:SelectExtensionsTest.cs


示例15: CreateUser

        private static void CreateUser(ActiveEventArgs e)
        {
            SelectList list = new SelectList {CssClass = "smallSelectList"};

            // Adding first static item...
            ListItem top = new ListItem(Language.Instance["ChooseUser", null, "Choose User..."], "0");
            list.Items.Add(top);

            string curValue = e.Params["Value"].Get<string>();
            foreach (User idxUser in ActiveType<User>.Select())
            {
                ListItem i = new ListItem(idxUser.Username, idxUser.Username);
                list.Items.Add(i);
                if (curValue == idxUser.Username)
                {
                    i.Selected = true;
                }
            }

            list.SelectedIndexChanged +=
                delegate(object sender, EventArgs e2)
                    {
                        SelectList lst = sender as SelectList;
                        if (lst == null)
                            return;
                        string[] xtra = lst.Xtra.Split('|');
                        int rowId = int.Parse(xtra[0]);
                        Whiteboard.Row row = ActiveType<Whiteboard.Row>.SelectByID(rowId);
                        Whiteboard.Cell cell = row.Cells.Find(
                            delegate(Whiteboard.Cell idx)
                                {
                                    return idx.Column.Caption == xtra[1];
                                });
                        cell.Value = lst.SelectedItem.Value;
                        cell.Save();
                        UpdateGridValue(e.Params["DataSource"].Value as Node, xtra[0], xtra[1], cell.Value);
                    };

            // Sending back our Control
            e.Params["Control"].Value = list;
        }
开发者ID:greaterwinner,项目名称:ra-brix,代码行数:41,代码来源:WhiteboardTypes.cs


示例16: DropDownListWrapper

 public DropDownListWrapper(SelectList dropDownList, string howFound)
     : base(howFound)
 {
     _dropDownList = dropDownList;
 }
开发者ID:ozgurtt,项目名称:FluentWebUITesting,代码行数:5,代码来源:DropDownListWrapper.cs


示例17: DropDownListUsesModelState

        public void DropDownListUsesModelState()
        {
            // Arrange
            SelectList selectList = new SelectList(MultiSelectListTest.GetSampleStrings());
            ViewDataDictionary viewData = GetViewDataWithErrors();
            viewData["foo"] = selectList;
            HtmlHelper helper = MvcHelper.GetHtmlHelper(viewData);

            // Act
            MvcHtmlString html = helper.DropDownList("foo");

            // Assert
            Assert.Equal(
                "<select class=\"input-validation-error\" id=\"foo\" name=\"foo\"><option>Alpha</option>" + Environment.NewLine
              + "<option selected=\"selected\">Bravo</option>" + Environment.NewLine
              + "<option>Charlie</option>" + Environment.NewLine
              + "</select>",
                html.ToHtmlString());
        }
开发者ID:AndreGleichner,项目名称:aspnetwebstack,代码行数:19,代码来源:SelectExtensionsTest.cs


示例18: Construct

    private void Construct(CharityRequirement charity)
    {
        if (charity == null)
            CharityRequirement = new CharityRequirement();
        else
            CharityRequirement = charity;

        var lookupRepository = new LookupRepository();

        var infrastructureTechnologies = lookupRepository.GetAllTechnologies();
        InfrastructureTechnologies = new SelectList(infrastructureTechnologies, "TechnologyID", "Description");
        SupportSkills = new SelectList(infrastructureTechnologies, "TechnologyID", "Description");
    }
开发者ID:JaySmith,项目名称:NwaGiveCamp,代码行数:13,代码来源:CharityController.cs


示例19: WriteSelected

        private void WriteSelected(SelectList selectList)
        {
            foreach (var option in selectList.Options)
            {
                Console.Write(option.Selected + ", ");
                var nativeElement = (IEElement)option.NativeElement;

                var htmlOptionElement = (mshtml.IHTMLOptionElement)nativeElement.AsHtmlElement;
                Console.WriteLine(htmlOptionElement.selected);
            }
            Console.WriteLine("----");
        }
开发者ID:koshdim,项目名称:KoWatIn,代码行数:12,代码来源:SelectListTests.cs


示例20: DropDownListWithObjectDictionaryAndTitle

        public void DropDownListWithObjectDictionaryAndTitle()
        {
            // Arrange
            HtmlHelper helper = MvcHelper.GetHtmlHelper(new ViewDataDictionary());
            SelectList selectList = new SelectList(MultiSelectListTest.GetSampleStrings());

            // Act
            MvcHtmlString html = helper.DropDownList("foo", selectList, "[Select Something]", HtmlHelperTest.AttributesObjectDictionary);

            // Assert
            Assert.Equal(
                "<select baz=\"BazObjValue\" id=\"foo\" name=\"foo\"><option value=\"\">[Select Something]</option>" + Environment.NewLine
              + "<option>Alpha</option>" + Environment.NewLine
              + "<option>Bravo</option>" + Environment.NewLine
              + "<option>Charlie</option>" + Environment.NewLine
              + "</select>",
                html.ToHtmlString());
        }
开发者ID:AndreGleichner,项目名称:aspnetwebstack,代码行数:18,代码来源:SelectExtensionsTest.cs



注:本文中的SelectList类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# SelectMode类代码示例发布时间:2022-05-24
下一篇:
C# SelectFileDialog类代码示例发布时间:2022-05-24
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap