老得不能再老的问题(DataGrid的嵌套)
想要达到的效果:
在ParentDataGrid中放置ChildDataGrid.两者上的数据为主子关系.ParentDataGrid的每一行都可以显示一个ChildDataGrid,最初始是不显示的,通过单击模板列中的一个ImageButton来控制显示与否.)
我的方法是:在模板列放置一个ImageButton,一个ChildDataGrid. 然后在ParentDataGrid的ItemDataBound事件中写ChildDataGrid的绑定事件.
出现的问题:绑定时老是出错,现在事件给出,请大侠们指教:
Public Sub DGItemDataBound(ByVal sender As Object, ByVal e As DataGridItemEventArgs)
Dim IBTNExpand1 As New ImageButton()
IBTNExpand1 = CType(e.Item.FindControl("IBTNExpand"), ImageButton)
If IBTNExpand1<>null Then '这句话肯定有错,VB中没有NULL,C#才有.
Dim ChildDataGrid1 As New DataGrid()
ChildDataGrid1 = CType(e.Item.FindControl("ChildDataGrid"), DataGrid)
Dim strSQL As String = "Select * from TblStockDetailForm where MainFormID=" + IBTNExpand1.CommandArgument
Dim TempSqlDA As New System.Data.SqlClient.SqlDataAdapter(strSQL, SqlConn) 'SqlConn是一个已存在的CONN
Dim TempDataSet As New DataSet()
TempSqlDA.Fill(TempDataSet, "TblStockDetailForm")
ChildDataGrid1.DataSource = TempDataSet.Tables("TblStockDetailForm").DefaultView
ChildDataGrid1.DataBind()
'End If
End Sub
急,感谢大家.