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

Posted on 2005-04-17
Last Modified: 2012-08-13
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?

Question by:ClaySeifert

    Author Comment

    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 :<)
    LVL 4

    Expert Comment

    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,

    Author Comment

    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?

    LVL 4

    Accepted Solution

    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,

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    What Security Threats Are You Missing?

    Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

    When pages do not download correctly, and you don't know why, the first thing you do is to look at the HTML source code of that page, but not all the downloaded files appear always clearly. If your source includes a javascript that computes the name…
    Both Easy and Powerful How easy is PHP? (  Very easy.  It has been described as "a programming language even my grandmother can use." How powerful is PHP?  http://en.wikiped…
    Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
    This video teaches users how to migrate an existing Wordpress website to a new domain.

    760 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    10 Experts available now in Live!

    Get 1:1 Help Now