Solved

How can you redirect to a multiple pages using a datalist

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

In .NET 2.0, Microsoft introduced the Web Site.  This was the default way to create a web Project in Visual Studio 2005.  In Visual Studio 2008, the Web Application has been restored as the default web Project in Visual Studio/.NET 3.x The Web Si…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, just open a new email message. In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
Hi friends,  in this video  I'll show you how new windows 10 user can learn the using of windows 10. Thank you.

867 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

12 Experts available now in Live!

Get 1:1 Help Now