473,466 Members | 1,290 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Get a hyperlink control inside a datalist when databouding

Hello,

Here is my datalist.
<asp:DataList 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>
</asp:DataList>

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!
Nov 17 '05 #1
0 2104

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Dave | last post by:
Hi , I have the following where I need to append a string variable inside a hyperlink template, inside a datalist. The variable 'categoryList' is the culprit. No matter where this variable is...
1
by: wsyeager36 | last post by:
I have a datagrid inside a datalist. The datalist shows parent info and the datagrid shows the child info for that parent. There is a checkbox on each row of the child datagrid. Also inside the...
1
by: bill yeager | last post by:
I have a datagrid control within a datalist control. When I try and do a "Find" on the control, the object comes back with nothing and then my pgm crashes. I am 100% sure that my datagird inside...
2
by: Big E | last post by:
I'm using ASP.Net and SQL Server. I have a table called states. I have 2 forms. On form 1 is the 50 states in textboxes created with a loop. I want to have those 50 or 45 or whatever amount of...
6
by: Davids | last post by:
having a 100% working aspx page I wanted to create a user control from a small DataList section (which has an ID="DataList1") of the page, so I created an ascx file with the DataList and Register...
0
by: vidhuraj | last post by:
hi all i have a hyperlink control and image control in my datalist i have binded the values for it ie, datalist will now display some images in image control and their corresponding ID in the...
0
by: debjanib | last post by:
I am trying to show a FAQ questionnaire set , with set of questions and then with the answers. At First there will be a list of questions and then then will be a list of questions and answers. ...
1
by: Salim | last post by:
Hi, I'm trying to get UniqueID of a linkbutton. I have 2 web user controls. And a master page. In fisrst web user control there is a datalist. In datalist ItemCreated event, I try to find...
1
by: Andy B | last post by:
I have this code: <asp:DataList id="NewsList" runat="server"> <HeaderTemplate> News list </HeaderTemplate> <ItemTemplate> <!-- news article code goes here --> </ItemTemplate>...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.