我正在使用ASP.NET 2.0。GridView SelectedIndexChange with Try Catch Block faulty in 2.0?
當我在我的事件中放置TRY CATCH塊時,它總是進入CATCH部分,在我的情況下,它將頁面重定向到Default.aspx。但是,如果我刪除了TRY CATCH塊,代碼就會執行得很好,並且它會按照它的設想執行。
Protected Sub gridResults1_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles gridResults1.SelectedIndexChanged
Try
Dim selectedRowIndex As Integer
selectedRowIndex = gridResults1.SelectedIndex
Dim row As GridViewRow = gridResults1.Rows(selectedRowIndex)
Dim theCompanyProfile As String = gridResults1.DataKeys(selectedRowIndex).Value
Response.Redirect("Report.aspx?ID=" + theCompanyProfile)
Catch ex As Exception
Response.Redirect("Default.aspx")
End Try
End Sub
- 沒有錯誤消息時我被「抓住EX作爲例外」放置一個破發點
- 難道我讀selectedRowIndex DataKey值不正確可能?
在此先感謝!
奇怪,你能嘗試登錄異常消息? – philjohn 2009-12-14 16:46:12
記錄信息是什麼意思?當我通過消息的所有屬性時,他們都說「錯誤:無法獲取值」 – Etienne 2009-12-14 16:53:05