Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP .Net Web Controls > Problem with Hyperlink to text files

Reply
Thread Tools

Problem with Hyperlink to text files

 
 
Shaheen.Pisces@gmail.com
Guest
Posts: n/a
 
      05-03-2007
Hello

i'm displaying the searched file names in data list. i want ti make
the filenames as hyperlink ...i wrote the following code


==================================================

<asp:Hyperlink


NavigateURL='<%# DataBinder.Eval(Container.DataItem,
"link.NavigateUrl")%>'
Target="_blank"
Text='<%# DataBinder.Eval(Container.DataItem,
"link.Text")%>'
runat="server" >
</asp:Hyperlink>
================================================

===================The Code Behind File=============
using System;
using System.Data;
using System.Text;
using System.IO;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class Presentation_Results : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{

ArrayList Results = (ArrayList)Session["FileData"];

string ErrorMessage = (string)Session["Message"];

if (ErrorMessage != null)
{
Literal2.Text = ErrorMessage;
}
else
{
ArrayList values = new ArrayList();

foreach (object s in Results)
{
ResultFiles re; //Struct object to store each
file name and its hit score

re = (ResultFiles)s;
if (re.totalHits > 0 )
{
values.Add(new ResultData1(re.link,
re.HitScore));
ResultData1.DataSource = values;
ResultData1.DataBind();
//i++;
}
else
{
Literal2.Text = "No Documents Found";
}
}
}}}


public class ResultData1
{
private float HitScore;
private System.Web.UI.WebControls.HyperLink link;
private int totalHits;


public ResultData1(System.Web.UI.WebControls.HyperLink links,
float hitscore, int totalhits)
{
link = new HyperLink();
this.link.ID = links.ID;
this.link.Text = links.Text;
this.link.NavigateUrl = links.NavigateUrl;
this.HitScore = hitscore;
this.totalHits = totalhits;
}

public System.Web.UI.WebControls.HyperLink Link
{
get
{
return link;
}
}

public float Hitscore
{
get
{

return HitScore;
}
}
}
}


================================================

this works fine means file name is displayed as a link and the
correct
path is shown in status bar but the problem is that when i click on
the file name nothing is happened. plz help in solving this problem
asap


Thanx
Shaheen

 
Reply With Quote
 
 
 
 
cbruen1@yahoo.com
Guest
Posts: n/a
 
      05-09-2007
On May 3, 9:41 pm, (E-Mail Removed) wrote:
> Hello
>
> i'm displaying the searched file names in data list. i want ti make
> the filenames as hyperlink ...i wrote the following code
>
> ==================================================
>
> <asp:Hyperlink
>
> NavigateURL='<%# DataBinder.Eval(Container.DataItem,
> "link.NavigateUrl")%>'
> Target="_blank"
> Text='<%# DataBinder.Eval(Container.DataItem,
> "link.Text")%>'
> runat="server" >
> </asp:Hyperlink>
> ================================================
>
> ===================The Code Behind File=============
> using System;
> using System.Data;
> using System.Text;
> using System.IO;
> using System.Configuration;
> using System.Collections;
> using System.Web;
> using System.Web.Security;
> using System.Web.UI;
> using System.Web.UI.WebControls;
> using System.Web.UI.WebControls.WebParts;
> using System.Web.UI.HtmlControls;
>
> public partial class Presentation_Results : System.Web.UI.Page
> {
> protected void Page_Load(object sender, EventArgs e)
> {
>
> ArrayList Results = (ArrayList)Session["FileData"];
>
> string ErrorMessage = (string)Session["Message"];
>
> if (ErrorMessage != null)
> {
> Literal2.Text = ErrorMessage;
> }
> else
> {
> ArrayList values = new ArrayList();
>
> foreach (object s in Results)
> {
> ResultFiles re; //Struct object to store each
> file name and its hit score
>
> re = (ResultFiles)s;
> if (re.totalHits > 0 )
> {
> values.Add(new ResultData1(re.link,
> re.HitScore));
> ResultData1.DataSource = values;
> ResultData1.DataBind();
> //i++;
> }
> else
> {
> Literal2.Text = "No Documents Found";
> }
> }
> }}}
>
> public class ResultData1
> {
> private float HitScore;
> private System.Web.UI.WebControls.HyperLink link;
> private int totalHits;
>
> public ResultData1(System.Web.UI.WebControls.HyperLink links,
> float hitscore, int totalhits)
> {
> link = new HyperLink();
> this.link.ID = links.ID;
> this.link.Text = links.Text;
> this.link.NavigateUrl = links.NavigateUrl;
> this.HitScore = hitscore;
> this.totalHits = totalhits;
> }
>
> public System.Web.UI.WebControls.HyperLink Link
> {
> get
> {
> return link;
> }
> }
>
> public float Hitscore
> {
> get
> {
>
> return HitScore;
> }
> }
> }
>
> }
>
> ================================================
>
> this works fine means file name is displayed as a link and the
> correct
> path is shown in status bar but the problem is that when i click on
> the file name nothing is happened. plz help in solving this problem
> asap
>
> Thanx
> Shaheen


I implemented the same thing but in a different way. I used a GridView
control to display a list of records, to which I added code in the
code behind to its OnRowDataBound event. The GridView control is bound
to a custom class that retrieves a record from the database. In the
aspx file you add:

<asp:GridView ID="applicationGrid"
OnRowDataBound="applicationGrid_OnRowDataBound"... ......</
asp:GridView>

Then in the code behind added the following:

protected void applicationGrid_OnRowDataBound(object sender,
GridViewRowEventArgs e)
{
string url = "";
Application newApp = e.Row.DataItem as Application;

if (newApp != null)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
url = "controller.aspx?edit=true&application_id="
+ newApp.ApplicationId + "&status=" + newApp.Status;
e.Row.Attributes["onclick"] =
"document.location.href='" + url + "'";
e.Row.Attributes.Add("onmouseover",
"this.style.cursor='pointer'");
}
}
}


The GridViewRowEventArgs parameter corresponds to a record containing
the data for each case in the list. I create a new instance of this,
grab the values I need, then construct the url and add the url to the
onclick attribute of the row.

Hope this helps.

Ciaran.

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Problem with Hyperlink to text files Shaheen.Pisces@gmail.com ASP .Net Web Controls 0 05-03-2007 08:29 PM
How to add a hyperlink column to asp.net datagrid - where only one value is a hyperlink davetichenor ASP .Net 1 10-30-2006 02:57 PM
How to add a hyperlink column to asp.net datagrid - where only one value is a hyperlink Dave ASP .Net Datagrid Control 0 10-21-2006 07:48 PM
ASP.NET 2.0 TreeView - node text as plain text (not hyperlink) Elton Pruitt ASP .Net 2 06-12-2006 12:41 PM
Dynamically Hyperlink and Event Handler for the Hyperlink ? Ken ASP .Net Datagrid Control 1 08-15-2003 11:38 PM



Advertisments