This is a migrated thread and some comments may be shown as answers.

GridButtonColumn Text Lost After Paging

1 Answer 69 Views
Grid
This is a migrated thread and some comments may be shown as answers.
James
Top achievements
Rank 1
James asked on 13 Dec 2011, 02:56 PM
I have a grid using GridBoundColumns.  The first column is a GridButtonColumn whose Text property is blank.  When the user clicks the button, the user's login Id is stored in a database table and the button's text is set to the user's login Id.  This all happens in the grid's ItemCommand event.  The code is:

        If e.CommandName = "Assign" Then
            Dim item As GridDataItem = CType(e.Item, GridDataItem)
            Dim strJobNumber As String = e.Item.OwnerTableView.DataKeyValues(e.Item.ItemIndex)("Job_Number")
            Dim strButtonText As String = CType(item("button").Controls(0), Button).Text
            Dim NTLoginID As String = GetCurrentUser()
              
            If String.IsNullOrEmpty(strButtonText) Then
                Dim _db As New MyAssembly.DataContext(ConfigurationManager.ConnectionStrings("MyCNString").ConnectionString)
                Dim rslt = _db.TMSearchAssignments.Where(Function(x) x.JobNumber.Equals(strJobNumber)).FirstOrDefault
                If Not rslt Is Nothing Then
                    CType(item("button").Controls(0), Button).Text = rslt.NTLoginID
                    Exit Sub
                Else
                    db.StoredProcedureRepo.sp_Insert_TMSearchAssignment(strJobNumber, NTLoginID, False)
                    CType(item("button").Controls(0), Button).Text = NTLoginID
                End If
            End If
End If

That code works great and the button's text is updated as desired. The problem is when the user goes to the next page in the grid and the returns to the previous page, the text is gone.  How can I keep the text from disappearing?

Thanks,

James

1 Answer, 1 is accepted

Sort by
0
James
Top achievements
Rank 1
answered on 13 Dec 2011, 04:00 PM
I was able to solve this by manually storing the button text in the viewstate and putting it back as needed in the Grid.PreRender event.
Tags
Grid
Asked by
James
Top achievements
Rank 1
Answers by
James
Top achievements
Rank 1
Share this question
or