大家好,我是新手,我正在为我的 asp.net 网站苦苦挣扎,我们的职责是制作兽医手术预订系统。
我有一个包含 4 个字段的 asp.net 页面,其中一个字段根据下面的 vb 代码在页面加载时填充。
我正在尝试获取下拉列表控件的选定值(或文本)并将其用作记录中第一个字段的值,但是每次我在下拉列表中选择第二个或第三个值并单击提交按钮时,新的创建的记录在下拉列表中插入第一个值。
希望你能帮忙。
Imports System.Linq
Imports System.Data.Linq
Partial Class _Default
Inherits System.Web.UI.Page
Protected Sub Page_Load(sender As Object, e As System.EventArgs) Handles Me.Load
Dim db As New LinQTASK5DataContext
Dim mu As MembershipUser = Membership.GetUser()
Dim g As Guid = mu.ProviderUserKey
Session.Item("uGUID") = g.ToString
Dim animal = From a In db.pets Where g = a.userGuid Select a.petName
Dim valSelec = animal
DropDownList1.DataSource = animal
DropDownList1.DataBind()
RangeValidator1.MinimumValue = DateTime.Now.ToString("dd/MM/yyyy")
RangeValidator1.MaximumValue = New DateTime(2100, 1, 1).ToString("dd/MM/yyyy")
End Sub
Protected Sub Button1_Click(sender As Object, e As System.EventArgs) Handles Button1.Click
Dim db As New LinQTASK5DataContext
Dim b As New booking With {.petName = DropDownList1.SelectedItem.Text, .VetID = cmbVet.Text, .Date = lblDate.Text, .slotID = cmbSlot.Text}
db.bookings.InsertOnSubmit(b)
db.SubmitChanges()
Response.Redirect("~/customers/viewbookings.aspx")
End Sub
End Class