gridview window.open not working

Last post 07-15-2009 6:40 AM by vinz. 1 replies.

Sort Posts:

  • gridview window.open not working

    07-15-2009, 5:25 AM
    • Member
      279 point Member
    • kirank28
    • Member since 05-18-2009, 6:49 AM
    • Posts 147

    protected void OnRowCreated(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                Desc = (String)DataBinder.Eval(e.Row.DataItem, "Act_Response");
                Actid = (int)DataBinder.Eval(e.Row.DataItem, "Actid");
                if (Desc != null)
                {
                    if (Desc.Length > 30)
                    {
                        Desc = Desc.Substring(0, 30) + "...";
                        Desc = "<a href='../Activity/viewActivity.asp?ActID="+Actid+"' onclick='javascript:window.open(this.href,'scrollbars,width=650,height=600'); return false'>" + Desc + "</a>";                    
                       
                    }
                }            
            }
        }



    hi window.open is not working in Gridview .

    and html is


    <asp:TemplateField HeaderText="Description">
                                                <ItemTemplate>
                                                    <%#Desc%>
                                                </ItemTemplate>
    </asp:TemplateField>



    Thank You,
    Kiran K.

    Remember to click “Mark as Answer” on the post,if it helps you.

    Coding Stuffs | Web Development help

    Mozilla Labs Projects
  • Re: gridview window.open not working

    07-15-2009, 6:40 AM
    Answer
    • All-Star
      90,423 point All-Star
    • vinz
    • Member since 10-05-2007, 11:47 AM
    • Cebu, Philippines
    • Posts 13,639
    • TrustedFriends-MVPs

    Add a Label to your template instead  like:

               <asp:TemplateField HeaderText="Header 3">
                    <ItemTemplate>
                        <asp:Label ID="Label1" runat="server" Text="Click Me"></asp:Label>
                    </ItemTemplate>
                </asp:TemplateField>


    Then at RowCreated event you can do something like this:

        protected void Gridview1_RowCreated(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                Label l = (Label)e.Row.FindControl("Label1");
                if (l != null)
                {
                    string script = "window.open('Default.aspx');";
                    l.Attributes.Add("onclick", script);
                }
            }
        }


    Best Regards,
    Vincent Maverick Durano
    SDE|Microsoft MVP - ASP/ASP.NET

    "Code,Beer and Music ~ my way of being a programmer"
Page 1 of 1 (2 items)