使用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
答案 0 :(得分:1)
我相信你想使用项目变量.srvc_id = CInt(item.Value)