Solved

How can you redirect to a multiple pages using a datalist

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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

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…
Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

743 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

13 Experts available now in Live!

Get 1:1 Help Now