KarenH1
asked on
Gridview Multiple HyperLinks in Single Cell - Part 2
I need to put multple hyperlinks in one cell in a gridview. Each row will contain different hyperlinks - different URL's and number of links.
I have read Question ID 23165167, and am trying to use that solution, but each row is adding on to the previous row's hyperlinks.
I am trying to get one link to appear correctly in the column at this point.
Here is my code:
Protected Sub grdOfferings_RowDataBound( ByVal sender As Object, ByVal e As System.Web.UI.WebControls. GridViewRo wEventArgs ) Handles grdOfferings.RowDataBound
For Each row As GridViewRow In grdOfferings.Rows
If e.Row.RowType = DataControlRowType.DataRow Then
Dim hl As New HyperLink
hl.Text = "Legal Appendix"
hl.NavigateUrl = HTTPPATH & "/" & LEGAL_APPENDIX_FILE_NAME
e.Row.Cells(0).Controls.Cl ear()
End If
Next
End Sub
I have read Question ID 23165167, and am trying to use that solution, but each row is adding on to the previous row's hyperlinks.
I am trying to get one link to appear correctly in the column at this point.
Here is my code:
Protected Sub grdOfferings_RowDataBound(
For Each row As GridViewRow In grdOfferings.Rows
If e.Row.RowType = DataControlRowType.DataRow
Dim hl As New HyperLink
hl.Text = "Legal Appendix"
hl.NavigateUrl = HTTPPATH & "/" & LEGAL_APPENDIX_FILE_NAME
e.Row.Cells(0).Controls.Cl
End If
Next
End Sub
you could put some hyperlinks on template column, on onrowdatabound if the row is datarow find those hyperlinks with findcontrol and put them the values that you need (text, navigateurl). you could even use the visible true/false of the hyperlinks if you don't need them on some row depending of your app logic.
ASKER
sorry, I posted the wrong code, last line before the end if is this:
e.Row.Cells(0).Controls.Ad d(hl)
My results are:
1st row: "Legal Appendix"
2 row: "Legal appendixLegalAppendix"
3 row: "Legal appendixLegalAppendixLegal appendix"
... and so on.
I only want one "Legal Appendix" URL per row.
How can I accomplish this?
e.Row.Cells(0).Controls.Ad
My results are:
1st row: "Legal Appendix"
2 row: "Legal appendixLegalAppendix"
3 row: "Legal appendixLegalAppendixLegal
... and so on.
I only want one "Legal Appendix" URL per row.
How can I accomplish this?
so
put a hyperlink in a template column of the gridview a hyperlink.
if you get your hyperlink values from the database use the rowdatabound event , find the hyperlink by id (e.Row.FindControl("Hyperl ink1") and put the values that you want on the hyperlink.
if you want i could give you an example but only in c#
put a hyperlink in a template column of the gridview a hyperlink.
if you get your hyperlink values from the database use the rowdatabound event , find the hyperlink by id (e.Row.FindControl("Hyperl
if you want i could give you an example but only in c#
Protected Sub grdOfferings_RowDataBound( ByVal sender As Object, ByVal e As System.Web.UI.WebControls. GridViewRo wEventArgs ) Handles grdOfferings.RowDataBound
If e.Row.RowType = DataControlRowType.DataRow Then
Dim hl As New HyperLink
hl.Text = "Legal Appendix"
hl.NavigateUrl = HTTPPATH & "/" & LEGAL_APPENDIX_FILE_NAME
e.Row.Cells(0).Controls.Cl ear()
End If
End Sub
dont loop in grid rows.. e ll gave u the row that is binding..
If e.Row.RowType = DataControlRowType.DataRow
Dim hl As New HyperLink
hl.Text = "Legal Appendix"
hl.NavigateUrl = HTTPPATH & "/" & LEGAL_APPENDIX_FILE_NAME
e.Row.Cells(0).Controls.Cl
End If
End Sub
dont loop in grid rows.. e ll gave u the row that is binding..
ASKER
Yes, please send me an example. I'm not following how I put a hyperlink in a template column.
This is what I have added so far:
<asp:TemplateField HeaderText="Documents"></a sp:Templat eField>
This is what I have added so far:
<asp:TemplateField HeaderText="Documents"></a
<asp:TemplateField HeaderText="Documents">
<asp:hyperlink runat=server id=hyp1 navigateurl='<% HTTPPATH & "/" & LEGAL_APPENDIX_FILE_NAME %>' >Legal Appendix </asp:hyperlink>
</asp:TemplateField>
<asp:hyperlink runat=server id=hyp1 navigateurl='<% HTTPPATH & "/" & LEGAL_APPENDIX_FILE_NAME %>' >Legal Appendix </asp:hyperlink>
</asp:TemplateField>
ASKER
Thanks, non_zero, removing the "for each row" eliminated the accumulated links in each row.
However, I am now getting an error: "type 'system.....templatefield' does not have a public property named 'hyperlink'.
Is "hyp1" the control I will search for and put my real url in? How will this work with a variable number of URL's? Some rows will have 2 URL's, some 4 URL's.
Thanks so much for your help
However, I am now getting an error: "type 'system.....templatefield'
Is "hyp1" the control I will search for and put my real url in? How will this work with a variable number of URL's? Some rows will have 2 URL's, some 4 URL's.
Thanks so much for your help
can u post what u wrote in templatefield with template field code
ooppss sorry
my fault...
this is the code
<asp:TemplateField HeaderText="Documents">
<itemtemplate>
<asp:hyperlink runat=server id=hyp1 navigateurl='<% HTTPPATH & "/" & LEGAL_APPENDIX_FILE_NAME %>' >Legal Appendix </asp:hyperlink>
</itemtemplate>
</asp:TemplateField>
my fault...
this is the code
<asp:TemplateField HeaderText="Documents">
<itemtemplate>
<asp:hyperlink runat=server id=hyp1 navigateurl='<% HTTPPATH & "/" & LEGAL_APPENDIX_FILE_NAME %>' >Legal Appendix </asp:hyperlink>
</itemtemplate>
</asp:TemplateField>
ASKER
One URL works, but I'm not understanding how to make this work for variable number of URL's per row. Can you be more specific?
Also, why does the URL appear in the first column of the grid. Can I force it to the last column?
Here is my HTML:
Legal Appendix
Here is my code behind:
Protected Sub grdOfferings_RowDataBound( ByVal sender As Object, ByVal e As System.Web.UI.WebControls. GridViewRo wEventArgs ) Handles grdOfferings.RowDataBound
If e.Row.RowType = DataControlRowType.DataRow Then
Dim hl As HyperLink = CType(e.Row.FindControl("h yp1"), HyperLink)
hl.Text = "Legal Appendix"
hl.NavigateUrl = HTTPPATH & LEGAL_APPENDIX_FILE_NAME
hl.Text = hl.Text & "View Bid"
hl.NavigateUrl = hl.NavigateUrl & HTTPPATH & "NEWONE2.PDF"
e.Row.Cells(0).Controls.Ad d(hl)
End If
Also, why does the URL appear in the first column of the grid. Can I force it to the last column?
Here is my HTML:
Legal Appendix
Here is my code behind:
Protected Sub grdOfferings_RowDataBound(
If e.Row.RowType = DataControlRowType.DataRow
Dim hl As HyperLink = CType(e.Row.FindControl("h
hl.Text = "Legal Appendix"
hl.NavigateUrl = HTTPPATH & LEGAL_APPENDIX_FILE_NAME
hl.Text = hl.Text & "View Bid"
hl.NavigateUrl = hl.NavigateUrl & HTTPPATH & "NEWONE2.PDF"
e.Row.Cells(0).Controls.Ad
End If
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thank you, I will use the "e.row.cells.count-1" index. The URL is coming from another field in the database. I will open another question for that. Thanks for your expert help!