Solved

How can you redirect to a multiple pages using a datalist

Posted on 2007-04-02
4
651 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
[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
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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
This is a high-level webinar that covers the history of enterprise open source database use. It addresses both the advantages companies see in using open source database technologies, as well as the fears and reservations they might have. In this…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…

728 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