Dears,
I have a webdatagrid with a bound filed that contains a URL sites as a string in my database, how I can format the field to be clickable as a link?
B R
Hello,
After investigating this further, I have determined that your requirement could be achieved by setting the column as TemplateDataField with an ‘a’ tag containing the value of the cell. The column could looks as follows:
<ig:TemplateDataField Key="Url" Header-Text="Url">
<ItemTemplate>
<a href='<%# DataBinder.Eval(((Infragistics.Web.UI.TemplateContainer)Container).DataItem, "Url")%>' target="_blank">
<%# DataBinder.Eval(((Infragistics.Web.UI.TemplateContainer)Container).DataItem, "Url")%>
</a>
</ItemTemplate>
</ig:TemplateDataField>
Please test it on your side and let me know if you need any further information regarding this matter.
Regards, Monika Kirkova, Infragistics
Thanks for you reply, but this is what I get when i try to but the <a> tag
Another suggestion would be to bind a method to the OnInitializeRow server side event. In this method the value for the ‘URL’ cell would be accessed and set as NavigateURL to the hyperlink. This could be achieved as follows:
<ig:WebDataGrid ID="WebDataGrid1" . . . OnInitializeRow="WebDataGrid1_InitializeRow">
<Columns>
<asp:HyperLink ID="HyperLink1" runat="server"></asp:HyperLink>
</Columns>
</ig:WebDataGrid>
Default.aspx.cs
protected void WebDataGrid1_InitializeRow(object sender, Infragistics.Web.UI.GridControls.RowEventArgs e)
{
DataRowView dataRowView = e.Row.DataItem as DataRowView;
var value = dataRowView.Row["Url"] as string;
(e.Row.Items[3].FindControl("HyperLink1") as HyperLink).NavigateUrl = value;
(e.Row.Items[3].FindControl("HyperLink1") as HyperLink).Text = value;
(e.Row.Items[3].FindControl("HyperLink1") as HyperLink).Target = "_blank";
}
Thanks Monika, I figured it out and this what I've done already, thank you for you support, I will verify your answer anyway.
I am glad that you were able to achieve your requirement.
Thank you for using Infragistics components.