Earlier we are using the Telerik Export Functionality. But if any row has null value it is not able to export the grid. So we have decied to create our one Export functionality. It is working fine but we are not able to export those data which is not visible in grid Right Now. After 15 Record it repeat the same row again and again. we are able to export those records which is visible. we tried to scroll down the record through coding but it still not working. Please suggest.
Actual Error:
1. Suppose Currently we have 100 Record in Grid and Page Size is 50. Currently we are able to see first 15 Records, Rest we can see if we scroll down and Record No : 1 is selected Record.
After Export: it exports all the 15 record correctly after 16th onwards it start repeating the same record no 16 till 100.
2. Suppose Currently we have 100 Record in Grid and Page Size is 50. Currently we are able to see 15 to 30 Records, Rest we can see if we scroll down and Record No : Record 35 is selected Record.
After Export: First it exports record No : 35 and then 15 to 30 records after that it start repeating the 30th record till 100.
How can we generate the UI of invisible Records?
Source Code Used for Exporting the Grid.
public string ExportDataGrid(bool withHeaders, RadGridView grid)
{
if (grid.ItemsSource == null)
return string.Empty;
System.Text.StringBuilder strBuilder = new System.Text.StringBuilder();
List<string> headers = new List<string>();
for (int i = 0; i < grid.Columns.Count; i++)
{
if(grid.Columns[i].IsVisible == true)
headers.Add(FormatCSVField(grid.Columns[i].Header.ToString()));
}
strBuilder.Append(String.Join(",", headers.ToArray())).Append("\r\n");
List<string> csvRow = new List<string>();
for (int j = 0; j < grid.Items.Count; j++)
{
grid.SetIsCurrent( grid.Items[j]);
grid.ScrollIntoView(grid.CurrentItem);
GridViewRow gvr = (GridViewRow)grid.ItemContainerGenerator.ContainerFromItem(grid.CurrentItem );
//Return the UI Element corrosponding to Given Item. Returns Null if the item doesn't belong to the item Collection or if No UI Has been generated for it.
csvRow.Clear();
foreach (GridViewCell gridViewCell in gvr.Cells)
{
if(gridViewCell.Column.IsVisible == true)
csvRow.Add(FormatCSVField((gridViewCell.Value == null ? string.Empty : gridViewCell.Value.ToString())));
}
strBuilder.Append(String.Join(",", csvRow.ToArray())).Append("\r\n");
}
return strBuilder.ToString();
}