简体   繁体   中英

how to maintain state for a table in asp.net

i am trying to upload a csv file data to DB. the process is like :

i am extracting csv file data to DataTable.

validating DataTable fields . if all good , loading them into DB on button click.

i am generating invTable at below validation method by passing saved csv file path on validate button click.

protected void ValidateData_Click(object sender, EventArgs e)
{
    ValidateCsv();
}

private void ValidateCsv(string fileContent)
{

    DataTable getCSVData;
    getCSVData = GetData(fileContent);
    invTable= Validate(getCSVData);
}

if am loading it on BulkUpload_Click, invTable is null. ideally it should have data , as assinged in ValidateCsv method.

  protected void BulkUpload_Click(object sender, EventArgs e)
    {
        MatchedRecords(invTable);
    }

any idea how to maintain invTable data across postback?

Change your ValidateCsv to a function.

private DataTable ValidateCsv(string fileContent)
{

    DataTable getCSVData;
    getCSVData = GetData(fileContent);
    invTable = Validate(getCSVData);

    return invTable;
}

Then on your MatchedRecords , modify it to accept a DataTable parameter.

private void MatchedRecords(DataTable invTable) {

}

Then on your BulkUpload_Click event, reference to the ValidateCsv , now a function that returns the value of your DataTable to the MatchedRecords void.

protected void BulkUpload_Click(object sender, EventArgs e)
{
    MatchedRecords(ValidateCsv('enter how you get the fileContent here...'));
}

Or

protected void BulkUpload_Click(object sender, EventArgs e)
{
    DataTable valueTable = ValidateCsv('enter how you get the fileContent here...');
    MatchedRecords(valueTable);
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM