在 telerik razor 控件的弹出窗口中编辑下拉列表问题

发布于 2024-11-07 12:36:15 字数 186 浏览 0 评论 0原文

我在 Telerik Razor Control 中创建了下拉列表。现在的问题是,当我单击“编辑”按钮 gridview 时,会出现一个弹出窗口,并且我得到的下拉列表中充满了值。bt 我没有获取选定的下拉列表值...我的意思是我没有获取所选记录的特定值。 .它给出了下拉列表中的所有值,就像我们单击“添加”按钮时得到的值一样......所以任何人都可以帮我吗

I have created dropdownlist in Telerik Razor Control. Now the problem is while i click on Edit button gridview one pop up window will come and i am getting dropdownlist filled with values..bt i am not getting selected dropdownlist value... i mean i am not getting particular value of selected records..its giving all the values in dropdownlist like what we are getting while we click on add button...so can anyone please help me out

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

扎心 2024-11-14 12:36:15

我知道这个答案迟了一年,但无论如何我都会发布。
对于 MVC:在网格中,使用字段的外键定义下拉列表,如下所示:

    @(Html.Kendo().Grid<YOURModel>()
                    .Name("yournameGrid")
                    .Columns(columns =>
                    {
                      columns.Bound(device => device.Id),
                      columns.ForeignKey(model => model.HeadSetId, (System.Collections.IEnumerable)ViewData["headsets"], "Id", "Name");
                    })
                     .DataSource(dataSource => dataSource
                        .Ajax()
                        .Model(model =>
                        {
                          model.Id(device => device.Id);
                          model.Field(d => d.HeadSetId).DefaultValue(ViewData["defaultHeadSetId"]);
                         })
                        .Read(read => read.Action("FunctionHere", "ControllerHere"))
       )

,在加载网格视图的函数中定义下拉列表的数据:

  PopulateDropdownList(); 

该函数看起来像这样:

    private void PopulateDropdownList()
    {
        var data= db.HeadSets.ToList()
                    .OrderBy(h => h.Name)
                    .Select(h => new HeadSet
                    {
                        Id = h.Id,
                        Name = h.Name
                    });
        ViewData["headsets"] = headSets;
        int hsID = 0;
        if (headSets.Count() > 0)
        {
            hsID = headSets.First().Id;
        }
        ViewData["defaultHeadSetId"] = hsID;
    }

然后在控制器中 弹出窗口(模板)定义 DropdownList:

   @(Html.Kendo().DropDownListFor(m => m.HeadsetId)
                .Name("HeadSetId") // THE NAME OF THE WIDGET MUST BE THE SAME AS THE PROPERTY!.
                .HtmlAttributes(new { @style = "margin-left:15px;" })
                .DataValueField("Id") // The value of the dropdown is taken from the item's Id property.
                .DataTextField("Name") // The text of the items is taken from the item's Name property.
                .BindTo((System.Collections.IEnumerable)ViewData["headsets"])// A list of all headsets which is populated in the controller.

            )

这应该正确地将记录的选定值绑定到下拉列表。

I know this answer is a year late but I ll post it anyway.
For MVC : In your grid, define the dropdownlist with the foreigkey for the field as such :

    @(Html.Kendo().Grid<YOURModel>()
                    .Name("yournameGrid")
                    .Columns(columns =>
                    {
                      columns.Bound(device => device.Id),
                      columns.ForeignKey(model => model.HeadSetId, (System.Collections.IEnumerable)ViewData["headsets"], "Id", "Name");
                    })
                     .DataSource(dataSource => dataSource
                        .Ajax()
                        .Model(model =>
                        {
                          model.Id(device => device.Id);
                          model.Field(d => d.HeadSetId).DefaultValue(ViewData["defaultHeadSetId"]);
                         })
                        .Read(read => read.Action("FunctionHere", "ControllerHere"))
       )

Then in your controller define the data for the dropdownlist in the function that is loading the view for the grid :

  PopulateDropdownList(); 

This function would look something like this :

    private void PopulateDropdownList()
    {
        var data= db.HeadSets.ToList()
                    .OrderBy(h => h.Name)
                    .Select(h => new HeadSet
                    {
                        Id = h.Id,
                        Name = h.Name
                    });
        ViewData["headsets"] = headSets;
        int hsID = 0;
        if (headSets.Count() > 0)
        {
            hsID = headSets.First().Id;
        }
        ViewData["defaultHeadSetId"] = hsID;
    }

In the pop up (template) define the DropdownList:

   @(Html.Kendo().DropDownListFor(m => m.HeadsetId)
                .Name("HeadSetId") // THE NAME OF THE WIDGET MUST BE THE SAME AS THE PROPERTY!.
                .HtmlAttributes(new { @style = "margin-left:15px;" })
                .DataValueField("Id") // The value of the dropdown is taken from the item's Id property.
                .DataTextField("Name") // The text of the items is taken from the item's Name property.
                .BindTo((System.Collections.IEnumerable)ViewData["headsets"])// A list of all headsets which is populated in the controller.

            )

This should correctly bind the selected value of the record to the dropdownlist.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文