ASP.NET GridViewのセルをクリックしてポップアップを表示する

GridViewの「セル」をクリックしてポップアップ画面を表示します。
表示している「文字列」ではありません。



<script type="text/javascript" >

function ShowPopup(str)    
{   
        var w = 150;
        var h = 100;
        var x = (screen.width  - w) / 2;
        var y = (screen.height - h) / 2;
        ChildWindow = window.open('Default2.aspx?TEL=' + str ,"", "width=" + w + ",height=" + h + ",top=" + y + ",left=" + x + ",dependent=yes,location=no,menubar=no,resizable=yes,scrollbars=no,status=no,titlebar=no,toolbar=no"); 

</script>


Imports System.Data



Partial Class _Default

    Inherits System.Web.UI.Page



    Protected Sub Page_Load(ByVal sender As ObjectByVal e As System.EventArgs) _

    Handles Me.Load

        If Not IsPostBack Then

            Dim dt As New DataTable

            dt.Columns.Add("CustomerID"GetType(String))

            dt.Columns.Add("CustomerNm"GetType(String))

            dt.Columns.Add("TEL"GetType(String))



            Dim row As DataRow

            For i As Integer = 1 To 10

                row = dt.NewRow

                row("CustomerID") = i.ToString

                row("CustomerNm") = "会社名" & i.ToString

                row("TEL") = i & i & i & "-" & i & i & i & i & "-" & i & i & i & i

                dt.Rows.Add(row)

            Next



            Me.GridView1.DataSource = dt

            Me.GridView1.DataBind()

        End If

    End Sub


 

    Protected Sub GridView1_RowDataBound(ByVal sender As ObjectByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) _

    Handles GridView1.RowDataBound

        If e.Row.RowType = DataControlRowType.DataRow Then

            Dim rowData As DataRowView = DirectCast(e.Row.DataItem, DataRowView)

            e.Row.Cells(1).Attributes.Add("OnClick"String.Format("ShowPopup('{0}');", rowData("Tel").ToString))

        End If

    End Sub

0 件のコメント: