0

我有一组 asp 隐藏字段控件,我希望根据我的数据表列名设置值,返回的列数不同,所以如果不使用,我将未使用的隐藏字段设置为 0。以下是我迄今为止所做的尝试,只是努力相应地设置正确的隐藏字段。

VB-

            Dim dt As DataTable
            Dim ds As New DataSet()
            ds = Getdata(4)
            dt = ds.Tables(0)

            Dim ColCnt As String = dt.Columns.Count 'Current ColCnt is 3
            For Each column As DataColumn In dt.Columns
                Select Case ColCnt
                    Case 2
                        hxValue.Value = column.ColumnName 'set to 1st Column Name
                        hxValue1.Value = 0 'Not used
                        hyValue.Value = column.ColumnName 'Set To 2nd Column Name
                    Case 3
                        hxValue.Value = column.ColumnName 'set to 1st Column Name
                        hxValue1.Value = column.ColumnName 'set to 2nd Column Name
                        hyValue.Value = column.ColumnName 'set to 3rd Column Name
                End Select
            Next
4

1 回答 1

0

试试这个,我认为你不需要For Each循环:

Dim ColCnt As Int = dt.Columns.Count 'Current ColCnt is 3    
Select Case ColCnt
    Case 2
        hxValue.Value = dt.Columns[0].ColumnName 'set to 1st Column Name
        hxValue1.Value = 0 'Not used
        hyValue.Value = dt.Columns[1].ColumnName 'Set To 2nd Column Name
    Case 3
        hxValue.Value = dt.Columns[0].ColumnName 'set to 1st Column Name
        hxValue1.Value = dt.Columns[1].ColumnName 'set to 2nd Column Name
        hyValue.Value = dt.Columns[2].ColumnName 'set to 3rd Column Name
End Select
于 2012-11-27T11:39:30.740 回答