Solved

Need "How To" Help with ASP.NET Dynamic List View

Posted on 2014-09-29
11
342 Views
Last Modified: 2014-10-01
Experts,

I'm struggling to come up with a "Best way" to solve a problem, and need your expert guidance.  I have an ASP.NET page that displays summarized data about employee work shifts.  This data is displayed in a list view.  Each line of the list view is summarized from one or more individual records in my SQL Server database.  I want to put a link on each line of the list view that the user can click.  Clicking this link would show a floating div with another list view that would show the detailed records from the database that rolled up to that summary line.  Inside this DIV would be a button to close (hide) the detailed view.

I already have a stored procedure written that would get the data for this DIV pop-up, which requires three parameters.  My desired flow is:

1. Summary ListView is populated on Page Load.

2. Each Row of ListView has a Details LinkButton. The Stored Procedure needs three parameters that are unique for each row of the ListView: Employee ID, Start DateTime, End DateTime.

3. When the user Clicks The Detail LinkButton, it fires a procedure that collects the three needed parameters from the row, passes them to the stored procedure, and uses the returned dataset to bind to the Details list view that is held in a floating Pop-Up style DIV.

4. When the user is done reviewing the detail data, they click the Close button in the pop-up div, and the div is hidden again.

5. I want all of this to be Asynch (working inside an update panel) so I don't want the link to fire out to a whole new page with query string parameters. I want it to be something where they click the detail button, the detail div pops up with the data in it, they close it, and move on down the list clicking the details button as desired to view the details for each employee, all without the page constantly being reloaded.


I know how to make it all work, except the part of how to structure the initial summary ListView LinkButton to initiate the procedure that would call the stored procedure, bind the result to the detail list view, and show the detail pop-up DIV.

Guidance?

Thanks,

John
0
Comment
Question by:John Parker
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 4
  • 2
11 Comments
 
LVL 15

Expert Comment

by:Ess Kay
ID: 40352373
Simply, when the user clicks the emplyee name, it passes the emplyee ID number to the method which gets the details

You can add alternate text there to keep the number


        <asp:ImageButton ID="ImageButton1" runat="server" ImageUrl="Images/Summary.png"
            OnClick="ImageButton_Click" AlternateText="id Number" />



Next, in your code you have the button click method

protected void ImageButton_Click(object sender, ImageClickEventArgs e)
        {
            string alternateText = (sender as ImageButton).AlternateText;
         YourFunctionToOpenDetailsPopup(   alternateText   );
         
        }
0
 
LVL 25

Expert Comment

by:apeter
ID: 40352382
Make a ajax call to get the details data to show in the pop up when clicking the link button. This will be fast and page is not loaded again.
0
 

Author Comment

by:John Parker
ID: 40352527
@esskayb2d, I need three parameters for the SP Call though...  How would I handle three parameters in your suggestion?

@apeter, what ASP.NET controls would you use to manage this ajax call?  I have these list views within an update panel, and was thinking this morning that I could just make a link in each line referencing the same page and add the three parameters I need into the query string.  If the postback had these three parameters, then the popup would be shown, but if they were not included, then the postback would do nothing.  if these links existed within the update panel, then this activity should be asynch and only affect the data within the update panel, correct?
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 15

Expert Comment

by:Ess Kay
ID: 40352725
I can think of a couple of ways you can pass 3 params.


1 - seperate the params with a delimiter IE : (*), then in the function, use regex or substring to get first second and 3rd
  Example  :
<asp:ImageButton ID="ImageButton1" runat="server" ImageUrl="Images/Summary.png"
            OnClick="ImageButton_Click" AlternateText="PARAM1*PARAM2*PARAM3" />
protected void ImageButton_Click(object sender, ImageClickEventArgs e)
        {
            string alternateText = (sender as ImageButton).AlternateText;
    String Params[2];

     int index = alternateText.IndexOf('*');
     Params[0]  = alternateText.Substring(0, index);  //GET FIRST PARAM
     index = alternateText.IndexOf('*', index + 1);
     Params[1]  = alternateText.Substring(Params[0].length+1, index);  //GET SECOND PARAM
     Params[2]  = alternateText.Substring( index + 1, alternateText.length );  //GET THIRDPARAM
         YourFunctionToOpenDetailsPopup(   alternateText   );
         str.Substring(0, str.IndexOf(' ', index + 1))
        }

Open in new window




2. Embed the criteria as SQL inside the AlternateText:

Example:
<asp:ImageButton ID="ImageButton1" runat="server" ImageUrl="Images/Summary.png"
            OnClick="ImageButton_Click" AlternateText=" WHERE param1 = 'x' AND param2 = 'y' AND param3 = 'z' " />
0
 

Author Comment

by:John Parker
ID: 40352731
Thanks esskayb2d.  I thought about doing a delimiter... that's definitely an option.  Thank you for your input!
0
 
LVL 15

Expert Comment

by:Ess Kay
ID: 40352752
You might want to avoid the sql way, if this is online, it will be easy to inject    something like "OR 1<>2   BEGIN DROP TABLE * ...."
0
 

Author Comment

by:John Parker
ID: 40352759
Agreed, that is why I was pushing the way of a stored procedure to handle the database interaction.

@apeter, I'm still interested in your feedback.

Thanks to you both!
0
 
LVL 15

Accepted Solution

by:
Ess Kay earned 250 total points
ID: 40352762
You can also pass as xml value <params><param1>X</param1><param2>2</param2><...></params>


This way you can just pass the whole string to the database, as an XML values, and handle from the stored procedure



declare @XML xml = '<ROOT><id>2013-01-01</id><id>2013-01-02</id></ROOT>'

select T.N.value('text()[1]', 'date') as id
from @XML.nodes('ROOT/id') as T(N)
0
 

Author Comment

by:John Parker
ID: 40352823
Ah, yes, that is a good idea as well.  Thank you!
0
 
LVL 25

Assisted Solution

by:apeter
apeter earned 250 total points
ID: 40353495
Your own ajax call will give you more control and how you control.  This link will give you more details on how to make ajax call in asp.net.  http://encosia.com/using-jquery-to-directly-call-aspnet-ajax-page-methods/

You can pass any number of parameters and return data accordingly.
0
 

Author Comment

by:John Parker
ID: 40354501
@apeter, thanks!  I'm going to split the points between both of you, as I think either solution is viable, and I appreciate you contributing your thoughts!  Thank you.
0

Featured Post

Enroll in May's Course of the Month

May’s Course of the Month is now available! Experts Exchange’s Premium Members and Team Accounts have access to a complimentary course each month as part of their membership—an extra way to increase training and boost professional development.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I have a large data set and a SSIS package. How can I load this file in multi threading?
Recently we ran in to an issue while running some SQL jobs where we were trying to process the cubes.  We got an error saying failure stating 'NT SERVICE\SQLSERVERAGENT does not have access to Analysis Services. So this is a way to automate that wit…
Via a live example combined with referencing Books Online, show some of the information that can be extracted from the Catalog Views in SQL Server.
Viewers will learn how to use the SELECT statement in SQL and will be exposed to the many uses the SELECT statement has.

738 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