Hi,
I have an implementation question which I'm hoping someone with much more experience and expertise could guide me in the right direction.
I need to load a batch of 5000 ~ 10,000 phone numbers into a database.
The user can select and upload a file using RadUpload and RadGrid with Paging turned on.
The user can preview, add, delete the record in the RadGrid and then click on 'Insert' button to load the phone numbers into database.
I'm really hoping to cache the data instead of using a saved file on the server for re-binding.
I think RadGrid only holds data for the current page, so what would be the best way to implement this?
Thank you in advance~
Helen
This is what I'm currently doing in code behind...newbie style!
protected
void
Page_Load(
object
sender, EventArgs e)
{
this
.tollFreeInventoryLogic = (TollFreeInventoryLogic)
this
.Session[SESSION_ATTR_NAME];
if
(tollFreeInventoryLogic ==
null
)
{
this
.tollFreeInventoryLogic =
new
TollFreeInventoryLogic();
this
.Session[SESSION_ATTR_NAME] =
this
.tollFreeInventoryLogic;
}
}
protected
void
RadButtonUploadToGrid_Click(
object
sender, EventArgs e)
{
string
targetFolder = RadUpload1.AppRelativeTemplateSourceDirectory + RadUpload1.TargetFolder;
string
fileName = targetFolder +
"/"
+ RadUpload1.UploadedFiles[0].GetName();
Session[
"fileName"
] = fileName;
GetDataFromMemory();
}
protected
void
GetDataFromFile()
{
if
(Session[
"fileName"
] !=
null
)
{
string
fileName = (
string
)Session[
"fileName"
];
try
{
using
(StreamReader sr =
new
StreamReader(Server.MapPath(fileName)))
{
string
tollFreeList = sr.ReadToEnd();
string
[] tollFreeArray = tollFreeList.Split(
new
string
[] { System.Environment.NewLine }, StringSplitOptions.None);
DataTable dt = CreateDataTable(tollFreeArray);
RadGrid1.DataSource = dt;
}
}
catch
(Exception err)
{
Console.WriteLine(
"The file could not be read:"
);
Console.WriteLine(err.Message);
}
}
}
protected
void
GetDataFromMemory()
{
foreach
(UploadedFile file
in
RadUpload1.UploadedFiles)
{
byte
[] bytes =
new
byte
[file.ContentLength];
file.InputStream.Read(bytes, 0, bytes.Length);
string
tollFreeList = System.Text.Encoding.Default.GetString(bytes);
string
[] tollFreeArray = tollFreeList.Split(
new
string
[] { System.Environment.NewLine }, StringSplitOptions.None);
DataTable dt = CreateDataTable(tollFreeArray);
RadGrid1.DataSource = dt;
RadGrid1.DataBind();
}
}
private
DataTable CreateDataTable(
string
[] tollFreeArray)
{
DataTable dt =
new
DataTable();
DataRow dr;
dt.Columns.Add(
"TollFreeNumber"
);
foreach
(
string
line
in
tollFreeArray)
{
//Debug.WriteLine(line);
if
(line.Trim().Length > 0)
{
dr = dt.NewRow();
dr[
"TollFreeNumber"
] = line;
dt.Rows.Add(dr);
}
}
return
dt;
}
protected
void
RadGrid1_NeedDataSource(
object
sender, GridNeedDataSourceEventArgs e)
{
GetDataFromFile();
}