TemplateFieldに「電話番号を表示」Buttonコントロールを配置します。
Protected Sub Page_Load(ByVal sender As Object, ByVal 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 Object, ByVal 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)
Dim btnShowTel As Button
btnShowTel = DirectCast(e.Row.FindControl("btnShowTel"), Button)
'ここでRowCommandで必要なデータを設定しておきます。
btnShowTel.CommandName = "btnShowTel"
btnShowTel.CommandArgument = rowData("TEL").ToString
End If
End Sub
Protected Sub GridView1_RowCommand(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewCommandEventArgs) _
Handles GridView1.RowCommand
'RowDataBoundで設定したCommandName、CommandArgumentを使用して、ラベルに電話番号を表示します。
If e.CommandName = "btnShowTel" Then
Dim tel As String = e.CommandArgument.ToString
Me.lblTel.Text = tel
End If
End Sub
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 Object, ByVal 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)
Dim btnShowTel As Button
btnShowTel = DirectCast(e.Row.FindControl("btnShowTel"), Button)
'ここでRowCommandで必要なデータを設定しておきます。
btnShowTel.CommandName = "btnShowTel"
btnShowTel.CommandArgument = rowData("TEL").ToString
End If
End Sub
Protected Sub GridView1_RowCommand(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewCommandEventArgs) _
Handles GridView1.RowCommand
'RowDataBoundで設定したCommandName、CommandArgumentを使用して、ラベルに電話番号を表示します。
If e.CommandName = "btnShowTel" Then
Dim tel As String = e.CommandArgument.ToString
Me.lblTel.Text = tel
End If
End Sub
0 件のコメント:
コメントを投稿