HyperlinkColumn 11

Last post 08-28-2008 10:01 AM by NC01. 9 replies.

Sort Posts:

  • HyperlinkColumn 11

    08-26-2008, 9:48 AM

     Hi ,

    I have the following datagrid where I'm passing some values.

    Normal 0 false false false MicrosoftInternetExplorer4 /* Style Definitions */ table.MsoNormalTable {mso-style-name:"Table Normal"; mso-tstyle-rowband-size:0; mso-tstyle-colband-size:0; mso-style-noshow:yes; mso-style-parent:""; mso-padding-alt:0in 5.4pt 0in 5.4pt; mso-para-margin:0in; mso-para-margin-bottom:.0001pt; mso-pagination:widow-orphan; font-size:10.0pt; font-family:"Times New Roman"; mso-ansi-language:#0400; mso-fareast-language:#0400; mso-bidi-language:#0400;}

    <asp:DataGrid ID="Dolphins" runat="server" AutoGenerateColumns="false">

        <Columns>

    <asp:BoundColumn DataField="Session" Visible="False"></asp:BoundColumn>

    <asp:BoundColumn DataField="Players" Visible="False"></asp:BoundColumn>

                       

    <asp:HyperLinkColumn DataNavigateUrlField="Session"   DataNavigateUrlFormatString="practices Session.aspx?Session={0}" DataTextField="Players"> </asp:HyperLinkColumn>

        </Columns>

    </asp:DataGrid>

     

     

    I also would like to pass this java scrip ("onClick", "javascript: window.location.href=' Session.aspx?games=' + CookieValue();") on the HyperlinkColum to the Session.aspx page. How can that be accomplis.

     

    thank you

     
  • Re: HyperlinkColumn

    08-26-2008, 10:26 AM
    • Contributor
      4,522 point Contributor
    • tompy_nation
    • Member since 02-28-2007, 10:45 AM
    • Gent
    • Posts 1,157

    in the onrowdatabound of your grid, locate that column and add your javascript. Something like this but modify it to find the correct column inside the row.

    And it it to the column instead of the row

     

    protected void gridLoginHistory_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType.Equals(DataControlRowType.DataRow))
            {
                e.Row.Attributes.Add("onmouseover", "javascript:this.style.cursor='hand';this.style.backgroundColor='#BAE0F2';");
                e.Row.Attributes.Add("onmouseleave", "javascript:this.style.cursor='default';this.style.backgroundColor='';");
            }
        }

    Don't forget to click "Mark as Answer" on the post that helped you.
  • Re: HyperlinkColumn

    08-26-2008, 11:55 AM
    • All-Star
      76,941 point All-Star
    • NC01
    • Member since 08-26-2005, 3:33 PM
    • Posts 14,335

    That would work on a GridView, but he said DataGrid. Here is the code for a DataGrid:

    protected void DataGrid1_ItemDataBound(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)
    {
     if ( (e.Item.ItemType == ListItemType.AlternatingItem) || (e.Item.ItemType == ListItemType.Item) )
     {
      e.Item.Style.Add("cursor", "hand");
      e.Item.Attributes.Add("onmouseover", "defColor=this.style.backgroundColor; this.style.backgroundColor='#BAE0F2';");
      e.Item.Attributes.Add("onmouseout", "this.style.backgroundColor=defColor;");
     }
    }

    Also change onmouseleave to onmouseout if you use the GridView code.

    NC...

  • Re: HyperlinkColumn

    08-27-2008, 11:29 AM

     I forgot to mention that I'm using VB this what I have so far

     Protected Sub DataGrid_ItemDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DataGridItemEventArgs)

            Try

                If (e.Item.ItemType = ListItemType.AlternatingItem) OrElse (e.Item.ItemType = ListItemType.Item) Then
                    e.Item.Style.Add("cursor", "hand")
                    e.Item.Attributes.Add("onmouseover", "defColor=this.style.backgroundColor; this.style.backgroundColor='#BAE0F2';")
                    e.Item.Attributes.Add("onmouseout", "this.style.backgroundColor=defColor;")
                End If
            Catch ex As Exception

            End Try

    But, know my question is where do I places the Javascript.

        End Sub

  • Re: HyperlinkColumn

    08-27-2008, 11:53 AM
    Answer
    • All-Star
      76,941 point All-Star
    • NC01
    • Member since 08-26-2005, 3:33 PM
    • Posts 14,335

    Sorry I missed that. Change your Grid as follows:

    <asp:DataGrid ID="DataGrid1" runat="server" AutoGenerateColumns="false" OnItemDataBound="DataGrid1_ItemDataBound">
        <Columns>
      <asp:BoundColumn DataField="Session" Visible="False"></asp:BoundColumn>
      <asp:BoundColumn DataField="Players" Visible="False"></asp:BoundColumn>
      <asp:templatecolumn headertext="Nbr">
       <itemtemplate>
        <asp:HyperLink ID="gridHyperLink runat="server"><%# Eval("Players") %></asp:HyperLink>
       </itemtemplate>
      </asp:templatecolumn>
        </Columns>
    </asp:DataGrid>

    And in the CodeBehind:

    protected void DataGrid1_ItemDataBound(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)
    {
     if ( (e.Item.ItemType == ListItemType.AlternatingItem) || (e.Item.ItemType == ListItemType.Item) )
     {
      e.Item.Style.Add("cursor", "hand");
      e.Item.Attributes.Add("onmouseover", "defColor=this.style.backgroundColor; this.style.backgroundColor='#BAE0F2';");
      e.Item.Attributes.Add("onmouseout", "this.style.backgroundColor=defColor;");

      HyperLink gridHyperLink = (HyperLink)e.Item.FindControl("gridHyperLink");

      if ( gridHyperLink != null )
      {
       string eventHandler = "window.location.href='Session.aspx?games=' + CookieValue();";
       gridHyperLink.Attributes.Add("onclick", eventHandler);
      }
     }
    }

    NC...

  • Re: HyperlinkColumn

    08-27-2008, 12:45 PM

      Normal 0 false false false MicrosoftInternetExplorer4 /* Style Definitions */ table.MsoNormalTable {mso-style-name:"Table Normal"; mso-tstyle-rowband-size:0; mso-tstyle-colband-size:0; mso-style-noshow:yes; mso-style-parent:""; mso-padding-alt:0in 5.4pt 0in 5.4pt; mso-para-margin:0in; mso-para-margin-bottom:.0001pt; mso-pagination:widow-orphan; font-size:10.0pt; font-family:"Times New Roman"; mso-ansi-language:#0400; mso-fareast-language:#0400; mso-bidi-language:#0400;}

     

    Now I have two problems with this

    1. I get the name of the players but I can’t click on them to go to Session.aspx page.

    2. The reason that I’m using a HyperLinkColum is because I’m passing other values and by changing my grid to this I’m not longer passing does values any more.

     

    <asp:DataGrid ID="DataGrid1" runat="server" AutoGenerateColumns="false" OnItemDataBound="DataGrid1_ItemDataBound">

      <Columns>

    <asp:BoundColumn DataField="Session" Visible="False"></asp:BoundColumn>

    <asp:BoundColumn DataField="Players" Visible="False"></asp:BoundColumn>

    <asp:TemplateColumn>

    <itemtemplate>

    <asp:HyperLink ID="gridHyperLink" runat="server"><%#Eval("Player")%></asp:HyperLink>

    </itemtemplate>

    </asp:TemplateColumn>

      </Columns>

    </asp:DataGrid>

     

    Protected Sub DataGrid1_ItemDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DataGridItemEventArgs)

     

            If (e.Item.ItemType = ListItemType.AlternatingItem) OrElse (e.Item.ItemType = ListItemType.Item) Then

                e.Item.Style.Add("cursor", "hand")

                e.Item.Attributes.Add("onmouseover", "defColor=this.style.backgroundColor; this.style.backgroundColor='#BAE0F2';")

                e.Item.Attributes.Add("onmouseout", "this.style.backgroundColor=defColor;")

     

                Dim gridHyperLink As HyperLink = DirectCast(e.Item.FindControl("gridHyperLink"), HyperLink)

     

                If gridHyperLink IsNot Nothing Then

     

                    Dim eventHandler As String = "window.location.href='Session.aspx?games=' + CookieValue();"

                    gridHyperLink.Attributes.Add("onclick", eventHandler)

     

                End If

     

            End If

     

        End Sub

  • Re: HyperlinkColumn

    08-28-2008, 8:45 AM

     Why do I need the red pill. I have no idea what your talking about.

  • Re: HyperlinkColumn

    08-28-2008, 8:50 AM
    • All-Star
      76,941 point All-Star
    • NC01
    • Member since 08-26-2005, 3:33 PM
    • Posts 14,335

    I have no idea of what you want. I have given you help enough for you to do this yourself.

    NC...

     

  • Re: HyperlinkColumn

    08-28-2008, 9:33 AM

    I did the changes that you told me to do and

    Now I have two problems with this

    1. I get the name of the players but I can’t click on them to go to Session.aspx page.

    2. The reason that I’m using a HyperLinkColum is because I’m passing other values and by changing the grid I’m not longer passing does values any more.

  • Re: HyperlinkColumn

    08-28-2008, 10:01 AM
    Answer
    • All-Star
      76,941 point All-Star
    • NC01
    • Member since 08-26-2005, 3:33 PM
    • Posts 14,335

    Try:

    Dim eventHandler As String = "Session.aspx?games=" + CookieValue();
    gridHyperLink.NavigateUrl = eventHandler


    NC...

     

Page 1 of 1 (10 items)