Opening Popup Window in ASP.NET to Search, Select, and Position on a Specific Record in a DataGrid.

Hi Experts,

I have an ASP.NET application written in VB.NET.  The main page lists customers via a datagrid that is populated from a SQL Server 2000 database.  The dagagrid allows paging (10 customers/page) and sorting using the builtin capabilities of the datagrid.  Currently there are approcimately 250 customers that get returned and placed in a dataset.  The dataset is used as the datasource for the datagrid on the main page.

Recently, the user asked for a popup window to allow them to search via the lastname.  They want the popup window as follows WITHOUT requiring a postback to the server.  They want to use the customer data that has been returned and that is in the dataset. Here is the scenario:

     1.  From the main window, click on an image control to open up the search window as a modal dialog (this app only runs on IE)
     2.  When the popup opens, enter a search string to find the customer on lastname.  
     3.  Searching is from left to right based on the number of characters entered.
     4.  Search on the lastname in the dataset displaying the results in a datagrid that is also in the popup window.  
     5.  Vertical scrolling is required in the popup window WITHOUT paging.
     6.  Select the desired record from the popup window datagrid and close the popup window.
     7.  Return the record selected and select the record in the datagrid on the main page.  
     8.  If the record selected isn't visible in the current page, go to the page where it is located and make it the current page.  
     9.  DO NOT change the sort sequence of the main datagrid.

I'm OK with all items except 4, 6, 7, and 8.  Any ideas on how to complete this?

Who is Participating?
jcrumbleConnect With a Mentor Commented:
If you want the page postitioned in the datagrid, something you might consider using is innerHTML, divs, iframes, or a panel inside the datagride as opposed to poping up a new page.  That would let you control the positioning without getting deep into DHTML that may not be interpreted by all browsers the same way.  As far as a postback goes your kind of stuck there unless you want to manually build your HTML tables from a javascript whenever the user searches the page.  This could work if you aren't using a ton of records.  Here's anpther discussion on JavaScript arrays that might help you with searching the array  Check out for other javascript that could help you emulate the datagrid capabilities on the client.

Good Luck,
ClaySeifertAuthor Commented:
Hi Experts

I was tired last night when I wrote the issue and it contains a mistake.  I said postback when I meant not having to re-query the database.  The application that this is for uses a copy of the database that gets updated nightly.  Sorry for the mis-type :<)
Just create a datatable and populate it on load.  You will then just bind and rebind to the same datatable/dataset based on the users paging etc.  Something I don't know for sure is if you can easily change a the attributes of a row in a daatgrid or if I have always wound using a datalis/repeater for this.  Assuming you can use a datagrid:
 Item 4 becomes like your existing page
 Item 6 is a simple Add.Attribute which would contain a window.close(); or container.close depending on how you call you popup window(I would look at javascript popup calendars to emulate that functionality)
 Item 7 & 8 could be as simple as populating a textbox containing an onChange event which would dynamically change the class name used in a particular row or alternatively have an add.attribute javascript that changes the of the row used in the datagrid from the popup window and then you can use the class attribute to determine what was selected, (but more than likely you would have to do a postback and repopulate the datagrid to display the selected record because it may not be on the displayed screen).

If you have to use a datalist, the same load premise will apply but you may need to manually recreate some of the datagrids functionality using ItemTemplates in your DataList.

If you still have problems with specifics in doing this let me know and I'll try to find some example code to post for you.

Good Luck,
ClaySeifertAuthor Commented:
Jeff has outlined a valid approach to solve this problem -- but I haven't been able to get it to work.  I'm stumbling with positioning the page containing the selected record so it is visable in the datagrid and subsequently selecting the record.  The selection of the record forces a postback using the built in event handler which I don't want.  Does anybody have javascript that can emulate my needs without forcing a postback?

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.