【问题标题】:How to add multiple attributes to a single data row in vb?如何在vb中为单个数据行添加多个属性?
【发布时间】:2013-04-02 14:24:09
【问题描述】:

这些属性可以组合成一行vb代码吗?

e.Row.Cells(1).Attributes.Add("id", "MyID")
e.Row.Cells(1).Attributes.Add("class", "MyCLASS")   

【问题讨论】:

    标签: asp.net vb.net attributes add


    【解决方案1】:

    不使用框架。如果真的需要一行行的话,写个方法吧……

    AddIdAndClassToCell(e.Row.Cells(1), "MyId", "MyClass")
    
    Private Sub AddIdAndClassToCell(cell, id, class)
        cell.Attributes.Add("id", id)
        cell.Attributes.Add("class", class)
    End Sub
    

    或者你可以做一个更通用的助手......

    Private Sub AddAttributes(cell, attributes As Dictionary(of String, String))
        For Each item As KeyValuePair(Of String, String) In attributes
            cell.Attributes.Add(item.Key, item.Value)
        Next
    End Sub
    

    【讨论】:

    • 这比我开始的代码要多=) 我实际上有两个以上的属性要添加。我只是想知道是否有一种速记方法可以将另一个 += 添加到行尾。
    • 这可能是更多的代码,但最终该方法可以被重用,从而为您省去输入冗余代码行的麻烦。亲吻
    猜你喜欢
    • 2015-09-14
    • 1970-01-01
    • 1970-01-01
    • 2017-11-22
    • 1970-01-01
    • 2013-04-20
    • 2020-02-21
    • 2020-11-03
    • 1970-01-01
    相关资源
    最近更新 更多