GridView控件的selectedIndex改不触发第一次点击 [英] Gridview selectedindex changed not firing on first click

查看:114
本文介绍了GridView控件的selectedIndex改不触发第一次点击的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

下面是我的code:

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

当我点击一排它被选中,但没有显示任何内容火灾和我的详细信息面板的第一次。当我点击了我第二次​​得到预期的结果。请你能告诉我怎么去解决这个问题呢?

When I click on a row for the first time it is selected but nothing fires and my details panel is not displayed. When I click for the second time I get the expected results. Please can you tell me how to get around this problem?

推荐答案

这是因为你在回传重新绑定。从您缠绕code Page_Load方法如下:

It's because you are rebinding on postback. Wrap the code from you Page_Load method as follows:

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

您可能需要移动,你​​改变DetailsPanel知名度出回传if语句的if语句。这是很难知道你想要做什么。

You might need to move the If statement where you change the DetailsPanel visibility out of the PostBack If statement. It's hard to know exactly what you want to do.

这篇关于GridView控件的selectedIndex改不触发第一次点击的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆