Solved

How can you redirect to a multiple pages using a datalist

Posted on 2007-04-02
4
648 Views
Last Modified: 2008-02-01
Hi,
I have a page with hyperlinks inside a datalist which are working fine.
In a code behind page I have the following code:

<asp:datalist id="dlReports" style="Z-INDEX: 102; LEFT: 376px; POSITION: absolute; TOP: 200px"
Font-Names="Verdana" Width="224px" Font-Name="Arial" CellSpacing="2" CellPadding="2" GridLines="none" Runat="server"
Font-Size="X-Small">
<HeaderTemplate>
</HeaderTemplate>
<ItemTemplate>
<asp:HyperLink runat="server" NavigateUrl ='<%#"Page1.aspx?ReportDate=" & DataBinder.Eval(Container.DataItem, "ReportDate", "{0:MM/dd/yyyy}").ToString() & "&Flag=" & DataBinder.Eval(Container.DataItem, "CompleteFlag") %>' ID="Hyperlink1">
<%#DataBinder.Eval(Container.DataItem, "ReportName")%>
</asp:HyperLink>
</ItemTemplate>
</asp:datalist>

But now I am trying to add another page - Page2.aspx to the same datalist but I am not sure how I can do this...
I think by running a sql statement -- I could check if my report date >= '02/23/2005' then I would want it
to go to Page2 else all other reports <= '02/23/2005'  to go to Page1...

ReportList.aspxb
Report_03/02/2005  <- hyperlink   (Page2.aspx)
Report_02/23/2005   (Page2.aspx)    
Report_02/16/2005   (Page1.aspx)  
Report_02/09/2005   (Page1.aspx)      
Report_02/02/2005   (Page1.aspx)

Could anyone help me...
Thanks!
0
Comment
Question by:avi4
4 Comments
 
LVL 3

Accepted Solution

by:
viveksg earned 500 total points
ID: 18841501
If u want to change the URL dynamically, better do it in server side (itemdatabound event).
Placea literal control instead of HyperLink control and manipulate it in itemdatabound.
ASPX PAGE
========
<asp:datalist id="dlReports" style="Z-INDEX: 102; LEFT: 376px; POSITION: absolute; TOP: 200px" Font-Names="Verdana" Width="224px" Font-Name="Arial" CellSpacing="2" CellPadding="2" GridLines="none" Runat="server"
Font-Size="X-Small">
<HeaderTemplate>
</HeaderTemplate>
<ItemTemplate>
<asp:Literal runat="server" ID="Literal1" Runat=''Server'>
<%#DataBinder.Eval(Container.DataItem, "ReportName")%>
</asp:HyperLink>
</ItemTemplate>
</asp:datalist>

C# PAGE
======
private void dlReports_ItemDataBound(object sender, DataListItemEventArgs e)
{
  if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType ==  
  ListItemType.SelectedItem || e.Item.ItemType == ListItemType.AlternatingItem)
 {
     Literal myLiteral = (Literal)e.Item.FindControl("Literal1");
     if (report_date >= '02/23/2005' )
           myLiteral.Text = "<a href='Page2.asp'>Click Here</a>";
    else
           myLiteral.Text = "<a href='Page1.asp'>Click Here</a>";
 }
}
0
 
LVL 1

Expert Comment

by:prabhuyogi
ID: 23303961
how i can split specify mutiple pages for the datalist .i dont understand if any idea


Thanks

Prabhu.M
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

In an ASP.NET application, I faced some technical problems. In this article, I list them out and show the solutions that I found.  I hope it will be useful. Problem: After closing a pop-up window, the parent page should be refreshed automaticall…
IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

808 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