Click here to Skip to main content
15,901,796 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi everybody,
I tried to make a hyperlink in gridbound template but fail..
any suggestion?
my link should like this : http://10.x.x.xxx:8080/field_name/ITDepartment/field_name

NavigateUrl='<%# String.Format("http://10.x.xx.xx:8080/Databinder.Eval(Container.DataItem,"YEAR")/ITDepartment/Databinder.Eval(Container.DataItem,NAME) %>'

My database table

ID | YEAR |FILENAME
1 | 2011 | ALPHA.DOC
2 | 2011 | BETA.PDF
3 |2012 | TEST.DOCX


Please guide me about this.

Thanks.
Posted
Updated 4-Jul-13 18:57pm
v4
Comments
Che Pak 5-Jul-13 4:52am    
i got from other forum.. just do like this..

NavigateUrl='<%# String.Format("http://10.x.xx.xx:8080"+ "/{0}/" + "ITDepartment/" + "{1}",Eval("Year"),Eval("FILENAME"))%>'

Try this...:)

C#
<asp:gridview id="GridView1" runat="server" autogeneratecolumns="False" width="241px" onrowdatabound="GridView1_RowDataBound" xmlns:asp="#unknown">
           <columns>
               <asp:templatefield>
                   <itemtemplate>
                       <asp:hyperlink id="HyperLink1" runat="server">HyperLink</asp:hyperlink>
                   </itemtemplate>
               </asp:templatefield>
               <asp:boundfield datafield="gender" />
           </columns>
       </asp:gridview>




C#
protected void Page_Load(object sender, EventArgs e)
    {
        DataTable table = new DataTable();
        table.Columns.Add("gender");
        DataRow dr = table.NewRow();
        dr["gender"] = "gril";
        table.Rows.Add(dr);
        this.GridView1.DataSource = table;
        GridView1.DataBind();
    }
    protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            if (e.Row.Cells[1].Text == "gril")
            {
                HyperLink hl = e.Row.FindControl("HyperLink1") as HyperLink;
                hl.NavigateUrl = "http://www.girl.com";
            }
        }
    }
 
Share this answer
 
Comments
Che Pak 5-Jul-13 1:12am    
Hi nirav, i want my link like this..
http://10.x.x.xxx:8080/field_name1/ITDepartment/field_name2
if I click the first ID
the link should be
http://10.x.x.xxx:8080/2011/ITDepartment/ALPHA.DOC
and so on..
where the changes is fieldname1 and fieldname2. thanks
My solution...

NavigateUrl='<%# String.Format("http://10.x.xx.xx:8080"+ "/{0}/" + "ITDepartment/" + "{1}",Eval("Year"),Eval("FILENAME"))%>'
 
Share this answer
 
Set your data as per this example:
XML
<pre lang="vb"><asp:hyperlink id="hyperlink1" runat="server"
text="Link"
navigateurl="&lt;%# "http://10.x.x.xxx:8080/2011/ITDepartment/" + Eval("ID").ToString() %&gt;" xmlns:asp="#unknown" /></pre>

ID means Your ALPHA.DOC.

Accept as answer and vote if help to you.
 
Share this answer
 
v2
Comments
Che Pak 5-Jul-13 1:01am    
Thanks jaideepsinh...but can your brief more detail..
jaideepsinh 5-Jul-13 1:29am    
Sorry, I don't know but its not my complete solution.Refer this:
<pre lang="vb"><asp:hyperlink id="hyperlink1" runat="server"
text="Link"
navigateurl="&lt;%# "~/YourPage.aspx?TaskID=" + Eval("ID").ToString() %&gt;" xmlns:asp="#unknown" /></pre>
Thanks7872 5-Jul-13 1:46am    
Can you explain what would the xmlns:asp="#unknown" do? Whats the relavance with the question?
jaideepsinh 5-Jul-13 1:58am    
Dear code project take its automatically i am not adding it.
Paste that in solution and see result.
Thanks7872 5-Jul-13 2:11am    
You posted something like:

Set your data as per this example:
" xmlns:asp="#unknown" />

Accept as answer and vote if help to you.


If codeproject added it automatically,then why you post it as answer? I asked you already that hows it related with the question?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900