I'm facing a low occurrence null reference exception accessing SellectedCells[] in a high volume WebDataGrid. The code is executed several hundred times a day, but I get 3-4 exceptions a week and I cannot determine why. I've added some explicit null checks to isolate what object is null and that only adds to the confusion. The WebDataGrid is bound to a basic DataSet and it is not possible for any "cell" in the DataSet to be empty much less null. I'm getting null reference exceptions on x=0 and x=1/2/6/etc. I cannot force duplicate this no matter how much I try so I have the following code added to trap/log occurrences as they happen in the production environment.
if (WebDataGridWaves.Behaviors.Selection.SelectedCells.Count != 0)
{
for (int x = 0; x < WebDataGridWaves.Behaviors.Selection.SelectedCells.Count; x++)
// Debug data for NullReferenceException accessing WebDataGridWaves
try
if (WebDataGridWaves.Behaviors.Selection.SelectedCells[x] == null)
Common.LogEvent("Error", "DeployConvergenceApplicationBySite", "SelectedCells[x] is null\r\n\r\nSite = " + sSite + "\r\nWebDataGridWaves.Behaviors.Selection.SelectedCells.Count = " + WebDataGridWaves.Behaviors.Selection.SelectedCells.Count.ToString() + "\r\nx = " + x.ToString());
}
else
if (String.IsNullOrEmpty(WebDataGridWaves.Behaviors.Selection.SelectedCells[x].Text))
Common.LogEvent("Error", "DeployConvergenceApplicationBySite", "SelectedCells[x].Text is NullOrEmpty\r\n\r\nSite = " + sSite + "\r\nWebDataGridWaves.Behaviors.Selection.SelectedCells.Count = " + WebDataGridWaves.Behaviors.Selection.SelectedCells.Count.ToString() + "\r\nx = " + x.ToString());
string sTemp = WebDataGridWaves.Behaviors.Selection.SelectedCells[x].Text;
catch (Exception ex)
Common.LogEvent("Error", "DeployConvergenceApplicationBySite", "Message:\r\n" + ex.Message + "\r\nStackTrace:\r\n" + ex.StackTrace + "\r\n\r\nSite = " + sSite + "\r\nWebDataGridWaves.Behaviors.Selection.SelectedCells.Count = " + WebDataGridWaves.Behaviors.Selection.SelectedCells.Count.ToString() + "\r\nx = " + x.ToString());
Here are some of the examples being logged:
Exception in DeployConvergenceApplicationBySite
SelectedCells[x] is null
Site = CTI_pl_bhw
WebDataGridWaves.Behaviors.Selection.SelectedCells.Count = 11
x = 6
Site = MEX
WebDataGridWaves.Behaviors.Selection.SelectedCells.Count = 10
x = 2
Site = KR
WebDataGridWaves.Behaviors.Selection.SelectedCells.Count = 4
x = 0
Any suggestions on why a SellectedCell[x] would be null when Count > x ?
Hello,
Thank you for contacting Infragistics!
I have done some looking into this matter and have some follow up questions concerning this matter:
What version of the Infragistics controls are you using?
How are you setting up the grid?
How are you setting up the selection behavior?
The code you use to look at the selected cells where is this being run?
I am following up to see if you can provide me with answers to my questions.
Please let me know if I may be of further assistance with this matter.
I've been out of office and returned today.
Version=13.2.20132.2255
Markup for grid is pretty simple.
<td><ig:WebDataGrid ID="WebDataGridWaves" runat="server"
Height="330px" Width="600px" AutoGenerateColumns="False" ShowHeader="False"
EnableDataViewState="True">
<EmptyRowsTemplate>
No Mappings Found</EmptyRowsTemplate>
<Columns>
<ig:BoundDataField DataFieldName="WaveName" Key="WaveName" Width="100%">
<Header Text="WaveName" />
</ig:BoundDataField>
</Columns>
<Behaviors>
<ig:Selection CellSelectType="Multiple" Enabled="true">
</ig:Selection>
</Behaviors>
</ig:WebDataGrid></td>
Data is bound using a DataSet returned from a SQL query that is a single column list with no null/blank rows.
DataSet waves = Common.GetDataSetSQL("EXEC [dbo].[GetAppWavesBySiteApplication] '" + WebDropDownSite.SelectedItem.Text + "', '" + HiddenField_DropDownGroupSelection.Value + "'");
WebDataGridWaves.DataSource = waves;
WebDataGridWaves.DataBind();
The user is clicking a button triggering postback which is when I'm getting the selected cells from the grid in the sample code posted originally.
Thank you for the update. Looking at what you have sent the only thing I see that stands out is that you set EnableDataViewState to true. The reason this is notable is that EnableDataViewState stores the data of the grid in view state when enabled. This can sometimes cause issues in some of the behaviors after reassigning or changing the data. It is most commonly an issue with updating as the old values end up getting persisted this way. I have some further questions concerning this matter. Do you set your data back to the datasource of the grid on every postback? If so how? Do you know what your users are doing just before this error occues? Are they just selecting cells then posting back? Or is there something else? At any point do you call clear on the selection behavior/selected cells collection?
In this page (it is a data entry form where they are just selecting a few dropdown items and cells in this grid) I don't need to rebind the datasource on postback because I'm just using the selected cell data from the viewstate. There is only one postback. I never clear the selected cells even after postback is complete. I leave them in case they want to change a dropdown value and perform another postback with the same cells selected.
There is a dropdown on the page that actually drives the grid population. With the viewstate item you mentioned if they submit the form then change that dropdown triggering a grid datasource change could the previous selected cell "count" be retained in the viewstate and then read on the next postback? I'm calling .ClearDataSource() binding the new one which should clear the selected cells, but maybe the viewstate data isn't always in sync?
I would like to when you call ClearDataSource to call clear on the selectedCells collection of the Selection behavior:
http://help.infragistics.com/doc/ASPNET/2014.2/CLR4.0/?page=Infragistics4.Web.v14.2~Infragistics.Web.UI.GridControls.SelectedCellCollection_members.html
WebDataGrid1.Selection.SelectedCells.Clear();
As the reason you may be seeing the issue is after clearing your datasource the selection behavior still has references to those selected cells event though they may not be valid any more.
Please let me know the results of this.
Thanks. I can deploy that change Wednesday and then monitor over the next week. I'll let you know...