Shiva-Kumar
asked on
Change datanavigateurlformatstring of hyperlinkfield at runtime
hi,
How do i change the DataNavigateUrlFormatStrin g of the given code below to "http://abcde.com/index.jsp?ID=2&question={0} at run time.
the ID is not coming from database, its based on the query string,
ex if lang = EN then ID = 1
if lang = ES then ID = 2
I have hidden field in my code which holds the ID based on the query string and i tried adding the refrence to the the datanavigateurlformatstrin g with no luck
DataNavigateUrlFormatStrin g = "http://abcde.com/index.jsp?ID='<%=ID.ClientID%>'&questio n={0}"
Please suggest any alternate suggestion.
Thanks
How do i change the DataNavigateUrlFormatStrin
the ID is not coming from database, its based on the query string,
ex if lang = EN then ID = 1
if lang = ES then ID = 2
I have hidden field in my code which holds the ID based on the query string and i tried adding the refrence to the the datanavigateurlformatstrin
DataNavigateUrlFormatStrin
Please suggest any alternate suggestion.
Thanks
<asp:GridView ID="Answer" runat="server" ShowHeader="False" ">
<Columns>
<asp:HyperLinkfield DataNavigateUrlFormatString = "http://abcde.com/index.jsp?ID=1&question={0}"
DataTextField="IRAnswer" DataNavigateUrlFields = "Answer" Target = "_blank" Text = "Click Here" />
</Columns>
</asp:Gridview>
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks for your help.
Hi,
The HyperLinkField does not have the ID property, hence You cannot directly reference it from code behind. However, simply convert the HyperLinkField to a template field and You can reference it from code behind.
The HyperLinkField does not have the ID property, hence You cannot directly reference it from code behind. However, simply convert the HyperLinkField to a template field and You can reference it from code behind.
Markup:
<asp:TemplateField>
<ItemTemplate>
<asp:HyperLink ID="HyperLink1" runat="server" NavigateUrl='<%# Eval("Answer", "http://abcde.com/index.jsp?question={0}")%>' Text="Answer">
</asp:HyperLink>
</ItemTemplate>
</asp:TemplateField>
Code behind:
Protected Sub GridView1_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles GridView1.RowDataBound
If e.Row.RowType = DataControlRowType.DataRow Then
Dim ID As Integer = 0
If Not String.IsNullOrEmpty(Request("lang")) Then
If Request("lang") = "EN" Then
ID = 1
ElseIf Request("lang") = "ES" Then
ID = 2
End If
End If
Dim hl As HyperLink = CType(e.Row.FindControl("HyperLink1"), HyperLink)
hl.NavigateUrl = hl.NavigateUrl.ToString + "&ID=" & ID
End If
End Sub
ASKER
That was perfect. Thanks buddy for all your help. It worked like a charm
Thanks