这是我的代码:
Protected Sub BookingsGV_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles BookingsGV.SelectedIndexChanged
BookingID = BookingsGV.SelectedValue
Dim query = From a In db.Approvers Where a.ApprovalStatus = False And a.BookingID = BookingID
Select a.ApproverEmail()
ApproverList.DataSource = query
ApproverList.DataBind()
EmailStatusLabel.Text = String.Empty
End Sub
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Dim query = From b In db.Bookings Where b.Approved = False And (From a In db.Approvers Where a.ApprovalStatus = False Select a.BookingID).Contains(b.BookingID) Select b.BookingID, b.DateRequired Distinct Order By DateRequired
BookingsGV.DataSource = query
BookingsGV.DataBind()
If ApproverList.Items.Count > 0 Then
DetailsPanel.Visible = True
Else
DetailsPanel.Visible = False
End If
End Sub
当我第一次单击某一行时,它会被选中,但不会触发任何内容,并且不会显示我的详细信息面板。当我第二次点击时,我得到了预期的结果。请问您能告诉我如何解决这个问题吗?
答案 0 :(得分:1)
这是因为你在回发时重新绑定。从您的Page_Load方法中包装代码如下:
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If Not IsPostBack
Dim query = From b In db.Bookings Where b.Approved = False And (From a In db.Approvers Where a.ApprovalStatus = False Select a.BookingID).Contains(b.BookingID) Select b.BookingID, b.DateRequired Distinct Order By DateRequired
BookingsGV.DataSource = query
BookingsGV.DataBind()
If ApproverList.Items.Count > 0 Then
DetailsPanel.Visible = True
Else
DetailsPanel.Visible = False
End If
End If
End Sub
您可能需要移动If语句,在其中将DetailsPanel可见性更改为PostBack If语句。很难确切地知道你想做什么。