Getting the selecteditem from gridview in ajax update panel
-
hi all, got a nasty one. Trying to get the selecteditem that a user clicks in an gridview, however the gridview is in an update panel. At first i thought the problem was with the session state - but what actually happens is the update panel does a postback sends everything back to the server but the server only sends back whats in the update panels. The main problem is when a user clicks the button, this causes an asynchronous postback the event fire in a different order to normal so i detected the button that was pressed after the page load event has fired and therefore miss capturing from session. Has anyone solved this? Here is my code: -
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load Dim selectedItemID As Integer = CType(Session("SelectedItemID"), Integer) End Sub
Protected Sub itemsGridView_RowCommand(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewCommandEventArgs) Handles itemsGridView.RowCommand Try Dim selectedItemID As Integer = CType(Session("SelectedItemID"), Integer) 'Check for custom CommandName Argument If e.CommandName = "SelectItem" Then ' Convert the row index stored in the CommandArgument ' property to an Integer. Dim index As Integer = Convert.ToInt32(e.CommandArgument) ' Retrieve the row that contains the ImageButton clicked ' by the user from the Rows collection. Dim row As GridViewRow = itemsGridView.Rows(index) ' Get a handle on ImageButton clicked Dim imgbtnItem As ImageButton imgbtnItem = row.Cells(13).Controls(0) selectedItemID = row.Cells(0).Text 'Session("SelectedItemID") = selectedItemID End If Catch ex As Exception MsgBox(ex.Message.ToString, MsgBoxStyle.Information, "ItemsGridView RowCommand Error!") End Try End Sub