C# と VB.NET の質問掲示板

わんくま同盟

ASP.NET、C++/CLI、Java 何でもどうぞ

C# と VB.NET の入門サイト


■98115 / )  Re[1]: TemplateFieldの動的追加について
□投稿者/ ポテロングしお味 (1回)-(2021/09/19(Sun) 16:39:21)
No98113 (Yammaer さん) に返信

こんな感じ

Class MyItemTemplate
    Implements ITemplate

    Public Sub InstantiateIn(ByVal container As System.Web.UI.Control) _
            Implements System.Web.UI.ITemplate.InstantiateIn

        Dim lblSyoruiName As New Label
        lblSyoruiName.ID = "lblSyoruiName"
        AddHandler lblSyoruiName.DataBinding, AddressOf lblSyoruiName_DataBind
        
        container.Controls.Add(lblSyoruiName)

    End Sub

    Sub lblSyoruiName_DataBind(sender As Object, e As EventArgs)
        Dim label = DirectCast(sender, Label)
        Dim container = DirectCast(label.BindingContainer, IDataItemContainer)
        label.Text = Convert.ToString(DataBinder.Eval(container.DataItem, "SyoruiName"), CultureInfo.CurrentCulture)
    End Sub

End Class

返信 編集キー/


管理者用

- Child Tree -