Get a hyperlink control inside a datalist when databouding

Discussion in 'ASP .Net' started by Arjen, Aug 4, 2003.

  1. Arjen

    Arjen Guest

    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!
     
    Arjen, Aug 4, 2003
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Dave
    Replies:
    0
    Views:
    805
  2. Nevyn Twyll
    Replies:
    8
    Views:
    1,874
  3. Andy B
    Replies:
    1
    Views:
    377
    Paul Shapiro
    Nov 21, 2008
  4. Dave
    Replies:
    0
    Views:
    430
  5. Roman
    Replies:
    2
    Views:
    264
    Roman
    Jan 4, 2005
Loading...

Share This Page