Home All Groups Group Topic Archive Search About

Problem with Hyperlink to text files

Author
3 May 2007 8:41 PM
Shaheen.Pisces
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

Author
9 May 2007 4:14 PM
cbruen1
On May 3, 9:41 pm, Shaheen.Pis***@gmail.com wrote:
Show quoteHide quote
> 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.