如何将字符串和数据绑定拆分为gridview?

时间:2013-09-12 09:08:23

标签: asp.net vb.net string gridview data-binding

我需要数据绑定其中字符串来自其他系统的gridview。

格式会是这样的:

A1|Peter|2011-01-01|2012-03-03|0;A9|Jacky|2011-10-01|2012-09-03|2;B3|Chris|2011-10-01|2012-09-03|2;

|作为列的分隔符

作为下一条记录的分隔符

有没有办法做到这一点?

感谢。

我的代码如下:

   Sub Call_Payroll(ByVal SNO As String)


        Dim theType As String = ""

        theType = xxxxxx <- Get from Source

        Dim tList = theType.Split(";")



        Dim dt As New DataTable

        dt = ListToDataTable(tList)

        RadGrid_payroll.DataSourceID = ""
        RadGrid_payroll.DataSource = dt
        RadGrid_payroll.DataBind()

    End Sub

    Public Shared Function ListToDataTable(Of T)(ByVal list As List(Of T)) As DataTable
        Dim dt As New DataTable()
        For Each info As PropertyInfo In GetType(T).GetProperties()
            dt.Columns.Add(New DataColumn(info.Name, info.PropertyType))
        Next
        For Each T In list
            Dim row As DataRow = dt.NewRow()
            For Each info As PropertyInfo In GetType(T).GetProperties()
                row(info.Name) = info.GetValue(T, Nothing)
            Next
            dt.Rows.Add(row)
        Next
        Return dt
    End Function

0 个答案:

没有答案