A
Arjen
Hello,
Here is my datalist.
<aspataList id="myDataList" CellPadding="4" Width="100%" runat="server">
<ItemTemplate>
<span class="Normal">
<asp:HyperLink id="link" Text='<%# Server.HtmlEncode((String)
DataBinder.Eval(Container.DataItem,"Title")) %>' NavigateUrl='<%#
DataBinder.Eval(Container.DataItem,"Url") %>' ToolTip='<%#
DataBinder.Eval(Container.DataItem,"Description") %>' runat="server" />
</span>
<br>
</ItemTemplate>
</aspataList>
I want to add to this hyperlink control the property target.
Some links should open inside a new window and some other not.
How can I do this?
I have tried this but it doesn't work.
private void myDataList_ItemDataBound(object sender,
System.Web.UI.WebControls.DataListItemEventArgs e) {
DataRowView drv = (DataRowView) e.Item.DataItem;
HyperLink link = (HyperLink) e.Item.FindControl("link");
if (Convert.ToBoolean(drv["NewWindow"]) == true){
link.Target = "_blank";
}
else {
link.Target = "_self";
}
}
Can somebody help me?
The error message was.
System.InvalidCastException: Specified cast is not valid.
On this line.
DataRowView drv = (DataRowView) e.Item.DataItem;
Thanks!
Here is my datalist.
<aspataList id="myDataList" CellPadding="4" Width="100%" runat="server">
<ItemTemplate>
<span class="Normal">
<asp:HyperLink id="link" Text='<%# Server.HtmlEncode((String)
DataBinder.Eval(Container.DataItem,"Title")) %>' NavigateUrl='<%#
DataBinder.Eval(Container.DataItem,"Url") %>' ToolTip='<%#
DataBinder.Eval(Container.DataItem,"Description") %>' runat="server" />
</span>
<br>
</ItemTemplate>
</aspataList>
I want to add to this hyperlink control the property target.
Some links should open inside a new window and some other not.
How can I do this?
I have tried this but it doesn't work.
private void myDataList_ItemDataBound(object sender,
System.Web.UI.WebControls.DataListItemEventArgs e) {
DataRowView drv = (DataRowView) e.Item.DataItem;
HyperLink link = (HyperLink) e.Item.FindControl("link");
if (Convert.ToBoolean(drv["NewWindow"]) == true){
link.Target = "_blank";
}
else {
link.Target = "_self";
}
}
Can somebody help me?
The error message was.
System.InvalidCastException: Specified cast is not valid.
On this line.
DataRowView drv = (DataRowView) e.Item.DataItem;
Thanks!