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

Grid not rebinding on postback

1 Answer 104 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Kevin
Top achievements
Rank 1
Kevin asked on 24 Apr 2014, 02:24 PM
I have a stiuation where becuase of how I load the page I need to stick in a fillGrid as boolean = false at the top of the load page to keep the NeedDataSource from firing.  I then turn it to true when it can fire and rebind the grid.  Everything works great up until I need to use the insert of the radgrid and then it bombs out.

  Protected Sub Page_Load(sender As Object, e As EventArgs) Handles Me.Load
        If Not IsPostBack Then
            Dim rspId As String = Request.QueryString("RSP")
 
            If rspId = String.Empty Then
                'Send to another page
            Else
                Dim userlogon As String = Split(Current.User.Identity.Name, "\")(1)
                HFUserId.Value = GetPersId(userlogon)
                HFRecruitId.Value = rspId
 
                LoadRSP(rspId)
                fillGridNotes = True
            End If
        End If
    End Sub
 
 
  Protected Sub myRadNotes_NeedDataSource(sender As Object, e As Telerik.Web.UI.GridNeedDataSourceEventArgs) Handles myRadNotes.NeedDataSource
        'Load the Notes Grid
        If fillGridNotes = True Then
            sql = "Select intRspNotesId, CONVERT(varchar(10), dtRSPNotesDateEntered, 111) dtNotes, strRSPNotesDesc, mn.strFullname + ' ' + ISNULL(' ' + strRank, '') LoggedBy from tblRSPNotes n LEFT JOIN MNNGPersonnel..tblMNNatPersonnel mn on " _
                & "mn.intPersonnelId = n.intLoggedBy where intRSPID in (Select intRSpId from tblRSp where intRecruitId = " & HFRecruitId.Value & ") Order by dtRSPNotesDateEntered DESC"
 
            myRadNotes.DataSource = getReader(sql)
        End If
    End Sub
 
 
 
Here is where I am having the problem though, becuase how can I set the boolean statement to true when posting back to do an insert statment on the radgrid.
 
Protected Sub myRadNotes_ItemCommand(sender As Object, e As Telerik.Web.UI.GridCommandEventArgs) Handles myRadNotes.ItemCommand
        If (e.CommandName = RadGrid.PerformInsertCommandName) Then
            fillGridNotes = True
            Dim editedItem As GridEditableItem = CType(e.Item, GridEditableItem)
            Dim notes As TextBox = DirectCast(editedItem.FindControl("txtNotes"), TextBox)
            Dim rspId As Integer = 16533
 
            sql = "Insert tblRSPNotes (intRSPId, dtRSpNotesDateEntered, strRSPNotesDesc, intLoggedBy) VALUES (" & rspId & ", '" & Date.Now & "', '" & sanitizeString(notes.Text) & "', " & HFUserId.Value & ")"
 
            insertUpdateDelete(sql)
 
            myRadNotes.Rebind()
        End If
    End Sub













































1 Answer, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 25 Apr 2014, 09:28 AM
Hi Kevin,

I guess you are loosing the Grid on postback because the fillGridNotes is always becoming false after postback. One suggestion is that you can store that variable in a session and use it through out.

VB:
'when you have fillGridNotes = true, set session of that value
fillGridNotes = True
Session("fillGridNotes") = fillGridNotes
. . .
Protected Sub RadGrid1_NeedDataSource(source As Object, e As Telerik.Web.UI.GridNeedDataSourceEventArgs)
    fillGridNotes = Convert.ToBoolean(Session("fillGridNotes"))        
    If fillGridNotes = True Then
       'Code to fill grid
    End If
End Sub

Thanks,
Princy
Tags
Grid
Asked by
Kevin
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Share this question
or