Grid View Column
-
I have a gridview that is populated via a datatable. What I am wanting to do is take the raw data from the datatable and create a set of bound columns and populate those columns with the values in the datatable. my code currently is as follows.
Dim datValTable As DataTable ' Create a dataTable to populate with the data Returned from the select statement. Dim datTable As DataTable datTable = New DataTable("ViewTable") datTable = PopulateDrillDown(datTable) GridView1.DataSource = datTable GridView1.DataBind() GridView1.Columns.Clear() Dim bFld As BoundField = Nothing bFld = New BoundField() bFld.DataField = "view_id" bFld.HeaderText = "ViewID" GridView1.Columns.Add(bFld) GridView1.DataBind()
This adds the ViewID column to all the columns from the datatable. which is obv not what i want. I need to be able to create a subset of columns from the datatable and populate my gridview with that. Can anyone point me in the right direction. Do i need to create a new datatable and populate that then bind on the gridview? Cheers Ian -
I have a gridview that is populated via a datatable. What I am wanting to do is take the raw data from the datatable and create a set of bound columns and populate those columns with the values in the datatable. my code currently is as follows.
Dim datValTable As DataTable ' Create a dataTable to populate with the data Returned from the select statement. Dim datTable As DataTable datTable = New DataTable("ViewTable") datTable = PopulateDrillDown(datTable) GridView1.DataSource = datTable GridView1.DataBind() GridView1.Columns.Clear() Dim bFld As BoundField = Nothing bFld = New BoundField() bFld.DataField = "view_id" bFld.HeaderText = "ViewID" GridView1.Columns.Add(bFld) GridView1.DataBind()
This adds the ViewID column to all the columns from the datatable. which is obv not what i want. I need to be able to create a subset of columns from the datatable and populate my gridview with that. Can anyone point me in the right direction. Do i need to create a new datatable and populate that then bind on the gridview? Cheers IanWhy not just return the columns you want in the first place? However, if you insist... you could either set the appropriate columns' width to zero, or else create a dataview with the columns you want out of the datatable and simply bind the datatable to that - there is no need to bind it to the datatable at all. Fred