我创建了一个数据访问层对象来处理查询执行。问题在于,当我调用它时,它最终会在Item_DataBound
两次运行,所以有些东西不在这里。提前谢谢。
Case "DataGrid"
If Len(DataValueField) > 0 Then
Dim oDS As New DataSet
Dim oDV As New DataView
oDV = DataTable.DefaultView
oDV.Sort = DataValueField & " ASC"
oDS.Tables.Add(oDV.ToTable)
CType(WebControl, DataGrid).DataSource = oDS
CType(WebControl, DataGrid).DataBind()
Else
CType(WebControl, DataGrid).DataSource = _DataSet
CType(WebControl, DataGrid).DataBind()
End If
CType(WebControl, DataGrid).DataSource = _DataSet
CType(WebControl, DataGrid).DataBind()
答案 0 :(得分:0)
根据不完整的代码段,无论DataValueField的长度是多少,都有两个DataBinds ......
Case "DataGrid"
If Len(DataValueField) > 0 Then
Dim oDS As New DataSet
Dim oDV As New DataView
oDV = DataTable.DefaultView
oDV.Sort = DataValueField & " ASC"
oDS.Tables.Add(oDV.ToTable)
CType(WebControl, DataGrid).DataSource = oDS
CType(WebControl, DataGrid).DataBind() 'FIRST IF DATAVALUEFIELD LEN>0
Else
CType(WebControl, DataGrid).DataSource = _DataSet
CType(WebControl, DataGrid).DataBind() 'FIRST IF DATAVALUEFIELD LEN=0
End If
CType(WebControl, DataGrid).DataSource = _DataSet
CType(WebControl, DataGrid).DataBind() 'SECOND DATABIND HAPPENS IN EITHER CASE