Tuesday, July 23, 2013

Gridview Link button click in asp.net

To open a new window on click of gridview link button in asp.net

VB.Net code

<asp:TemplateField HeaderText="View">
                                    <ItemTemplate>
                                        <asp:LinkButton ID="linkButton" runat="server" CommandName='<%#dataBinder.Eval(Container.DataItem,"ID").ToString()%>'
                                            Text='View Attendance' OnClick="linkButton_Click" CausesValidation="false"></asp:LinkButton>
                                    </ItemTemplate>
                                </asp:TemplateField>

Protected Sub linkButton_Click(ByVal sender As Object, ByVal e As EventArgs)
        Dim Str As String = sender.CommandName.ToString()
        Dim Url As String = "Sample.aspx" & "?id=" & Str
        Dim UrlScript As String = ""
        UrlScript = "<script language='javascript'>window.open('" & Url & "', 'Export', 'location=0,status=0,scrollbars=1,toolbar=0,menubar=0,directories=0'); </script>"
        Page.ClientScript.RegisterStartupScript([GetType], "JavaScript", UrlScript)
    End Sub

No comments:

Post a Comment