I tried to export the data to excel using radgrid option, it's working fine on single export. but I tried to export in for each loop, last file data's only exported. Is possible to export in loop?
protected void btnexport_Click(object sender, EventArgs e)
{
string selectedimportfilesid = "";
IList<radlistboxitem> collection = ListBoxFileNames.CheckedItems;
string selectedfilename = "";
DataTable dtselect = new DataTable();
foreach (RadListBoxItem item in collection)
{
Label filename = (Label)item.FindControl("lblfilename");
Label Importfileid = (Label)item.FindControl("lblimportfileid");
selectedfilename = filename.Text;
selectedimportfilesid = Importfileid.Text;
dtselect = selectedexportfilelist(selectedimportfilesid);
testgrid.DataSource = dtselect;
testgrid.DataBind();
testgrid.ExportSettings.IgnorePaging = true;
testgrid.ExportSettings.FileName = selectedfilename
testgrid.ExportSettings.OpenInNewWindow = true;
testgrid.ExportSettings.Excel.FileExtension = "xls";
testgrid.MasterTableView.ExportToExcel();
}
}
protected void btnexport_Click(object sender, EventArgs e)
{
string selectedimportfilesid = "";
IList<radlistboxitem> collection = ListBoxFileNames.CheckedItems;
string selectedfilename = "";
DataTable dtselect = new DataTable();
foreach (RadListBoxItem item in collection)
{
Label filename = (Label)item.FindControl("lblfilename");
Label Importfileid = (Label)item.FindControl("lblimportfileid");
selectedfilename = filename.Text;
selectedimportfilesid = Importfileid.Text;
dtselect = selectedexportfilelist(selectedimportfilesid);
testgrid.DataSource = dtselect;
testgrid.DataBind();
testgrid.ExportSettings.IgnorePaging = true;
testgrid.ExportSettings.FileName = selectedfilename
testgrid.ExportSettings.OpenInNewWindow = true;
testgrid.ExportSettings.Excel.FileExtension = "xls";
testgrid.MasterTableView.ExportToExcel();
}
}