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

Grid postback on edit insert show nothing

1 Answer 50 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Kevin
Top achievements
Rank 1
Kevin asked on 16 Apr 2015, 08:17 PM

I had to put in a Boolean value on my grid to trigger it in certain situations to fill or not.  however with the gird features of insert and edit turned on it will not show them on postback so I cannot do insert or edits with template editform's.  I know I have resolved this long ago but can't find location or my old ticket.

 It only happens when I click on edit form or insert to grid and I get blank grid line, but if I hit refresh again there is the edit or insert information, so I know it has to do Boolean statement.

 

Dim fundGrid As Boolean = False
 
 
Protected Sub myFundGrid_ItemCommand(sender As Object, e As Telerik.Web.UI.GridCommandEventArgs) Handles myFundGrid.ItemCommand
       If (e.CommandName = "Archive") Then
           Dim fundId As Integer = e.CommandArgument
 
           sql = "Update Drat_FundSource set bitArchive = 1 where intFundID = " & fundId
 
           insertUpdateDelete(sql)
 
           fundGrid = True
           myFundGrid.Rebind()
       End If
 
       If (e.CommandName = RadGrid.PerformInsertCommandName AndAlso e.Item.OwnerTableView.Name = "FundGrid") Then
           Dim editedItem As GridEditableItem = CType(e.Item, GridEditableItem)
           Dim source As DropDownList = DirectCast(editedItem.FindControl("ddlSource"), DropDownList)
           Dim pgm As TextBox = DirectCast(editedItem.FindControl("txtPGm"), TextBox)
           Dim eor As TextBox = DirectCast(editedItem.FindControl("txtEOR"), TextBox)
           Dim mdep As TextBox = DirectCast(editedItem.FindControl("txtMDEP"), TextBox)
           Dim ams As TextBox = DirectCast(editedItem.FindControl("txtAMSCOS"), TextBox)
 
           sql = "Insert Drat_FundSource (intSourceId, strPGMCDNum,strEORNum, strMDepNum, strAMSCOSNum, dtEntered, intEnteredBy) VALUES (" & source.SelectedValue & ", '" & sanitizeString(pgm.Text.ToUpper) & "', " _
               & "'" & sanitizeString(eor.Text.ToUpper) & "', '" & sanitizeString(mdep.Text.ToUpper) & "', '" & sanitizeString(ams.Text.ToUpper) & "', '" & Date.Now & "', " & GetUserId() & ")"
 
           insertUpdateDelete(sql)
 
           fundGrid = True
           myFundGrid.Rebind()
       End If
 
       If (e.CommandName = RadGrid.UpdateCommandName AndAlso e.Item.OwnerTableView.Name = "FundGrid") Then
           Dim editedItem As GridEditableItem = CType(e.Item, GridEditableItem)
           Dim fundId As Integer = e.Item.OwnerTableView.DataKeyValues(e.Item.ItemIndex)("ID")
           Dim source As DropDownList = DirectCast(editedItem.FindControl("ddlSource"), DropDownList)
           Dim pgm As TextBox = DirectCast(editedItem.FindControl("txtPGm"), TextBox)
           Dim eor As TextBox = DirectCast(editedItem.FindControl("txtEOR"), TextBox)
           Dim mdep As TextBox = DirectCast(editedItem.FindControl("txtMDEP"), TextBox)
           Dim ams As TextBox = DirectCast(editedItem.FindControl("txtAMSCOS"), TextBox)
 
           sql = "Update Drat_FundSource set intSourceId = " & source.SelectedValue & ", strPGMCDNum = '" & sanitizeString(pgm.Text.ToUpper) & "', strEORNum = '" & sanitizeString(eor.Text.ToUpper) & "', " _
               & "strMDepNum = '" & sanitizeString(mdep.Text.ToUpper) & "', strAMSCOSNum = '" & sanitizeString(ams.Text.ToUpper) & "' where intFundId = " & fundId
 
           insertUpdateDelete(sql)
 
           fundGrid = True
           myFundGrid.Rebind()
       End If
   End Sub
 
 
 Protected Sub myFundGrid_NeedDataSource(sender As Object, e As Telerik.Web.UI.GridNeedDataSourceEventArgs) Handles myFundGrid.NeedDataSource
       If fundGrid = True Then
           Dim sqlwhere As String
           If cbhistory.Checked = True Then
               sqlwhere = String.Empty
           Else
               sqlwhere = "  where bitArchive IS NULL"
           End If
 
           sql = "Select ds.intFundId ID, intSourceId, CASE WHEN ds.intSourceId = 1 then 'FEDERAL' ELSE 'STATE' END SOURCE, ds.strPGMCDNum PGMCD, ds.strEORNum EOR, ds.strMDepNum MDEP, ds.strAmscosNum AMSCOS, " _
                  & "Convert(varchar(10), ds.dtEntered, 111) DATE, mn.strFullName + ' \ ' + strRank NAME from Drat_FundSource ds INNER JOIN MnNgPersonnel.dbo.tblMNNatPersonnel mn on mn.intPersonnelId = intEnteredBy " _
                  & sqlwhere
 
           myFundGrid.DataSource = getData(sql)
       End If
   End Sub

1 Answer, 1 is accepted

Sort by
0
Angel Petrov
Telerik team
answered on 21 Apr 2015, 08:21 AM
Hi Kevin,

Most probably the logic inside the NeedDataSource handler is not executed. Please verify that the below line of code is executed.

VB:
myFundGrid.DataSource = getData(sql)

Additionally I noticed that .Rebind() is called for the grid when insert or update is initiated. Have in mind that this is not mandatory as the control will rebind itself automatically. That said I suggest removing the rebinding logic from the ItemCommand handler.

Regards,
Angel Petrov
Telerik
 

See What's Next in App Development. Register for TelerikNEXT.

 
Tags
Grid
Asked by
Kevin
Top achievements
Rank 1
Answers by
Angel Petrov
Telerik team
Share this question
or