Problem with Hyperlink to text files

Discussion in 'ASP .Net Web Controls' started by Shaheen.Pisces@gmail.com, May 3, 2007.

  1. Guest

    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
     
    , May 3, 2007
    #1
    1. Advertising

  2. Guest

    On May 3, 9:41 pm, 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.
     
    , May 9, 2007
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Elton Pruitt
    Replies:
    2
    Views:
    5,833
    akjoshi
    Jun 12, 2006
  2. davetichenor
    Replies:
    1
    Views:
    856
    Eliyahu Goldin
    Oct 30, 2006
  3. Ken
    Replies:
    1
    Views:
    396
    Alvin Bruney
    Aug 16, 2003
  4. Dave
    Replies:
    0
    Views:
    968
  5. Problem with Hyperlink to text files

    , May 3, 2007, in forum: ASP .Net Web Controls
    Replies:
    0
    Views:
    113
Loading...

Share This Page