I am trying to make a column a hyperlink in my grid view. I am Using Umbraco 6 childpages as datasource. I have a link but at the moment it's going to /website/masterpages/url with %20% in the spaces
My View is like this:
<asp:hyperlinkfield datatextfield="title" datanavigateurlfields="title" headertext="Title" />
and code behind like this:
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
HyperLinkField title = new HyperLinkField();
string[] dataNavigateUrlFields = { "title" };
title.DataTextField = "title";
title.DataNavigateUrlFields = dataNavigateUrlFields;
title.HeaderText = "Title";
title.DataNavigateUrlFormatString = "item.Url";
// Create a BoundField object to display the company's city.
DataTable dt = new DataTable();
dt.Columns.AddRange(new DataColumn[3] { new DataColumn("title", typeof(String)),
new DataColumn("lastUpdated", typeof(string)),
new DataColumn("theme",typeof(string)) });
int i = 0;
foreach (var item in uQuery.GetCurrentNode().ChildrenAsList)
{
var dateTimeString = item.GetProperty("lastUpdated").Value.ToString();
var dateTime = System.Xml.XmlConvert.ToDateTime(dateTimeString);
dt.Rows.Add(item.Name, dateTime.ToString("dd.MM.yyyy"), item.GetProperty("theme").Value.ToString());
}
Session["data"] = dt;
Cache["Data"] = dt;
Practice.DataSource = dt;
Practice.DataBind();
}
can anyone tell me what I'm doing wrong - thanks
I figured it out, but adding an extra column to the table called name (as this is not displayed unless you reference it on the output, removing:
HyperLinkField title = new HyperLinkField();
string[] dataNavigateUrlFields = { "title" };
title.DataTextField = "title";
title.DataNavigateUrlFields = dataNavigateUrlFields;
title.HeaderText = "Title";
title.DataNavigateUrlFormatString = "item.Url";
// Create a BoundField object to display the company's city.
and changing the datatextfield to "name" ie DataTextField="name".
If anyone else gets stuck:)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.