I need a bunch of GridViews to display on my page which is determined by different categories... all gridview DataField are the same... I just want to categorized it into different gridview.
I had done some google and I found some make sense example... but it ends with "NOT WORK"... because it ends with "does make sense."
at HTML side, I do this:
Server side:
Private dynamicGrids() As GridView Private Sub getBOMComp() Dim ds1 As New DataSet Dim iGV As Integer = 0 Try If SQLConnected() Then
ds1 = getBOMCompTitle()
If dsCheck(ds1) Then
dynamicGrids = New GridView(ds1.Tables(0).Rows.Count - 1) {}
For Each r As DataRow In ds1.Tables(0).Rows
Dim dynGridView As New GridView
iGV += 1
dynGridView.ID = "Gridview" + (iGV).ToString
setGVColumnsProperties(dynGridView, r("brdBomTtl").ToString)
PopulateGrids(dynGridView, r("brdBomTtl").ToString)
gridPlaceHolder.Controls.Add(dynGridView)
dynamicGrids(iGV - 1) = dynGridView
Dim literalBreak As LiteralControl = New LiteralControl("<br />")
gridPlaceHolder.Controls.Add(literalBreak)
Next
End If
End If
Catch ex As Exception
PromptError(ex.Message)
End Try
End Sub
Private Sub PopulateGrids(ByRef gv As GridView, ByVal strTitle As String) Dim ds As New DataSet Try If SQLConnected() Then strSQL = "SELECT brdLvl,itemNo,parentRef,partDesc,ORev,NRev,OQty," _ & " NQty,ORefDesc,NRefDesc,diffRefDesc,[brdRemark" _ & " FROM rsSnBomComp WHERE sn = '" & Session("sn") & "'" _ & " AND brdBomTtl ='" & strTitle & "' order by [brdLvl;" ds = SQLExecuteQuery(strSQL) If dsCheck(ds) Then gv.DataSource = ds.Tables(0) gv.DataBind() End If End If Catch ex As Exception PromptError(ex.Message) End Try End Sub
Private Sub setGVColumnsProperties(ByRef gv As GridView, strTitle As String)
Try
gv.AutoGenerateColumns = False
gv.BorderStyle = BorderStyle.None
gv.BorderWidth = 1
gv.CellPadding = 3
'gv.Height = "100%"
gv.BackColor = Drawing.Color.White
gv.BorderColor = System.Drawing.ColorTranslator.FromHtml("#CCCCCC")
gv.FooterStyle.BackColor = Drawing.Color.White
gv.FooterStyle.ForeColor = System.Drawing.ColorTranslator.FromHtml("#000066")
gv.HeaderStyle.BackColor = System.Drawing.ColorTranslator.FromHtml("#006699")
gv.HeaderStyle.Font.Bold = True
gv.HeaderStyle.ForeColor = Drawing.Color.White
gv.PagerStyle.BackColor = Drawing.Color.White
gv.PagerStyle.ForeColor = System.Drawing.ColorTranslator.FromHtml("#000066")
gv.PagerStyle.HorizontalAlign = HorizontalAlign.Left
gv.RowStyle.ForeColor = System.Drawing.ColorTranslator.FromHtml("#000066")
gv.SelectedRowStyle.BackColor = System.Drawing.ColorTranslator.FromHtml("#006699")
gv.SelectedRowStyle.Font.Bold = True
gv.SelectedRowStyle.ForeColor = Drawing.Color.White
gv.SortedAscendingCellStyle.BackColor = System.Drawing.ColorTranslator.FromHtml("#F1F1F1")
gv.SortedAscendingHeaderStyle.BackColor = System.Drawing.ColorTranslator.FromHtml("#007DBB")
gv.SortedDescendingCellStyle.BackColor = System.Drawing.ColorTranslator.FromHtml("#CAC9C9")
gv.SortedDescendingHeaderStyle.BackColor = System.Drawing.ColorTranslator.FromHtml("#00547E")
'strSQL = "SELECT [brdLvl],[itemNo],[parentRef],[partDesc],[custORev],[custNRev],[custOQty]," _
' & " [custNQty],[custORefDesc],[custNRefDesc],[diffRefDesc],[brdRemark]" _
' & " FROM [rsSnBomComp] WHERE [sn] = '" & Session("sn") & "'" _
' & " AND [brdBomTtl]='" & strTitle & "' order by [brdLvl];"
Dim col01 As BoundField = New BoundField()
col01.DataField = "brdLvl"
col01.HeaderText = "Board Level"
col01.HeaderStyle.HorizontalAlign = HorizontalAlign.Center
col01.ItemStyle.HorizontalAlign = HorizontalAlign.Center
col01.ControlStyle.CssClass = strTitle
gv.Columns.Add(col01)
Dim col02 As BoundField = New BoundField()
col02.DataField = "itemNo"
col02.HeaderText = "Item Number"
col02.ItemStyle.Width = 120
col02.ItemStyle.HorizontalAlign = HorizontalAlign.Left
col02.ControlStyle.CssClass = strTitle
gv.Columns.Add(col02)
Dim col03 As BoundField = New BoundField()
col03.DataField = "[parentRef]"
col03.HeaderText = "Parent Ref"
col03.ItemStyle.Width = 120
col03.ItemStyle.HorizontalAlign = HorizontalAlign.Left
col03.ControlStyle.CssClass = strTitle
gv.Columns.Add(col03)
Dim col04 As BoundField = New BoundField()
col04.DataField = "[partDesc]"
col04.HeaderText = "Desciption"
col04.ItemStyle.Width = 120
col04.ItemStyle.HorizontalAlign = HorizontalAlign.Left
col04.ControlStyle.CssClass = strTitle
gv.Columns.Add(col04)
Dim col05 As BoundField = New BoundField()
col05.DataField = "[custORev]"
col05.HeaderText = "Cust_Old Rev"
col05.ItemStyle.Width = 100
col05.ItemStyle.HorizontalAlign = HorizontalAlign.Center
col05.HeaderStyle.HorizontalAlign = HorizontalAlign.Center
col05.ControlStyle.CssClass = strTitle
gv.Columns.Add(col05)
Dim col06 As BoundField = New BoundField()
col06.DataField = "[custNRev]"
col06.HeaderText = "Cust_New Rev"
col06.ItemStyle.Width = 100
col06.ItemStyle.HorizontalAlign = HorizontalAlign.Center
col06.HeaderStyle.HorizontalAlign = HorizontalAlign.Center
col06.ControlStyle.CssClass = strTitle
gv.Columns.Add(col06)
Dim col07 As BoundField = New BoundField()
col07.DataField = "[custOQty]"
col07.HeaderText = "Cust_Old Qty"
col07.ItemStyle.Width = 100
col07.ItemStyle.HorizontalAlign = HorizontalAlign.Center
col07.HeaderStyle.HorizontalAlign = HorizontalAlign.Center
col07.ControlStyle.CssClass = strTitle
gv.Columns.Add(col07)
Dim col08 As BoundField = New BoundField()
col08.DataField = "[custNQty]"
col08.HeaderText = "Cust_New Qty"
col08.ItemStyle.Width = 100
col08.ItemStyle.HorizontalAlign = HorizontalAlign.Center
col08.HeaderStyle.HorizontalAlign = HorizontalAlign.Center
col08.ControlStyle.CssClass = strTitle
gv.Columns.Add(col08)
Dim col09 As BoundField = New BoundField()
col09.DataField = "[custORefDesc]"
col09.HeaderText = "Cust_Old Ref Des"
col09.ItemStyle.HorizontalAlign = HorizontalAlign.Left
col09.ControlStyle.CssClass = strTitle
gv.Columns.Add(col09)
Dim col10 As BoundField = New BoundField()
col10.DataField = "[custNRefDesc]"
col10.HeaderText = "Cust_New Ref Des"
col10.ItemStyle.HorizontalAlign = HorizontalAlign.Left
col10.ControlStyle.CssClass = strTitle
gv.Columns.Add(col10)
Dim col11 As BoundField = New BoundField()
col11.DataField = "[diffRefDesc]"
col11.HeaderText = "Diff_Ref Des"
col11.ItemStyle.HorizontalAlign = HorizontalAlign.Left
col11.ControlStyle.CssClass = strTitle
gv.Columns.Add(col11)
Dim col12 As BoundField = New BoundField()
col12.DataField = "[brdRemark]"
col12.HeaderText = "Comment"
col12.ItemStyle.HorizontalAlign = HorizontalAlign.Left
col12.ControlStyle.CssClass = strTitle
gv.Columns.Add(col12)
SetGroupHeader(gv)
Catch ex As Exception
PromptError(ex.Message)
End Try
End Sub
at the end... I got no out at all... I really out of idea what should I do... please help