【问题标题】:LINQ - SELECT NEW - Include ListBox Selected ItemsLINQ - SELECT NEW - 包括列表框选定项
【发布时间】:2014-01-30 14:25:43
【问题描述】:

使用 ASP.NET 4.0

我在 LINQ 上遇到问题,无法将 .srvc_id 设置为选中的值,而我在下面的查询仅填充了我的对象的第一个复选框。

代码

If Not IsNothing(lbServices.SelectedItem) Then
            'NEW record INSERT values from list box to table.
            myServices = (From item In lbServices.Items
                                    Where item.Selected
                                    Select New tbl_parent_to_child With
                                            {
                                                    .id = myServices.child_id,

                                                    ----- .srvc_id is where I am stuck any help would be great.  It is repeating the first selected check box.

                                                    .srvc_id = lbServices.SelectedValue,
                                                    .Active = True,
                                                    .CreateDate = DateTime.Now,
                                                    .CreateByID = SecurityMethods.GetLoginUserId(Session("AuthUser")),
                                                    .UpdateDate = DateTime.Now,
                                                    .UpdateByID = SecurityMethods.GetLoginUserId(Session("AuthUser"))
                                            }).ToList()
            For Each item In myServices 
                ctx.tbl_parent_to_child .Add(item)
            Next
        End If

Try
            ctx.SaveChanges()
        Catch ex As Exception
            Me.Master.HandleStatusMessageEvent((New StatusMessageEventArgs("Email a screen shot of this error to the Help Desk", StatusMessageType.ErrorMsg)))
        End Try

【问题讨论】:

    标签: asp.net vb.net linq


    【解决方案1】:

    我相信你想使用 item 变量,.srvc_id = CInt(item.Value)

    这类似于Listbox in asp.net not getting selected items

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-02-27
      • 1970-01-01
      相关资源
      最近更新 更多