Hello All... This is my first post so please be gentle with me and I will try to explain the issue I've been fighting with for 3 days.
I am trying to update a gridview element from a different thread. This update task is part of an outer foreach loop that need to hold until the user has completed their selections in the updated gridview.
I shall try to describe the function here:
Every object below is contained inside an AJAX UpdatePanel
I call a function from a button.
This method parses the input from an asp:textbox and adds it to a string array via a split on the ";" character.
I then process each entry with a foreach loop.
In the foreach loop I perform a search on the entry and check whether the search returns multiple results or a single result.
If the search returns multiple results then I want to hold the foreach loop and add the those results to a popup gridview.
Once the user has completed selecting the appropriate gridview results they click a close button on the gridview popup and the foreach loop should continue as before until another entry with multiple search results is found.
I have tried to solve this using threading and an AutoResetEvent object, but until now I have had no success.
I seem to run into the issue that the user interface locks up and does not display the GridView
Example:
// instantiate the AutoResetEvent object static AutoResetEvent wh = new AutoResetEvent(false); // method to process user input protected void btn_ResolveUserInput_Click(object sender, EventArgs e) { // split user input into string array string[] usrInput = tbx_UserInput.Text.Split(';'); // process each entry in the array foreach(string entry in usrInput) { // search database or what not for results corresponding to the current entry being prcessed ArrayList results = new ArrayList(SearchStuff(entry)) // if the entry being process returned multiple results process here if(result.Count > 1) { Thread workerThread = new Thread(new ThreadStart(delegate() { // create dataset and datatable to bind to gridview later DataSet dsMultipleResults = new DataSet(); DataTable dtMultipleResults = dsMultipleResults.Tables.Add("MultipleResults"); // create columns for datatable dtMultipleResults.Columsn.Add("ResultName"); // instantiate row in datatable DataRow drMultipleResults = null; // process each of the multiple results retruned and add to datatable foreach(string resultName in results) { drMultipleResults = dtMultipleResults.NewRow(); drMultipleResults["ResultName"] = resultName; dtMultipleResults.Rows.Add(drMultipleResults); } // bind datatabel to gridview gridView.DataSource = dsMultipleResults.Tables[0]; gridView.DataBind(); })).Start(); wh.WaitOne(); } } } // method to close multiple results dialogue protected void btn_CloseMultipleResultsDialogue_Click(object sender, EventArgs e) { wh.Set(); }
can't you use AJAX ModelPopupExtender to show data in Grid inside this ModelPopupExtender ?