Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. BoundField in GRidView

BoundField in GRidView

Scheduled Pinned Locked Moved Visual Basic
questioncsharpcssasp-netannouncement
1 Posts 1 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • B Offline
    B Offline
    BobsAfro
    wrote on last edited by
    #1

    I have a datatable which I would like to be able to set properties for each column to display as a gridview. I am creating a boundfield or checkboxfield etc.. for each column. These fields are set to have have there datafields from the datatable. Trouble is when i bind the datatable to the gridview I end up with boundfield version of the column and the original. How can I only show the boundfields or whatever? Hope this makes sense. I am still very new to asp.net I will include my code incase it helps.

    Public Function buildGrid(ByVal DS As DataSet, ByVal ChartDetails As DataTable, ByVal GridID As Integer, ByVal TableId As Integer) As GridView
    Dim Grid As New GridView
    Dim oTemp As Object
    Dim oboundCol As BoundField
    'Declare and fill dataview
    Dim dv As DataView
    dv = New DataView
    dv.Table = ChartDetails
    Dim ColumnID As Integer
    Dim DataGrid As New DataTable
    DataGrid = DS.Tables(TableId - 1).Copy
    dv.Sort = "ColumnID ASC"
    Dim ods As New ObjectDataSource

        Dim ColCount As Integer = 0
        While ColCount < DataGrid.Columns.Count
            ColumnID = ColCount + 1
            dv.RowFilter = "ColumnID = '" & ColumnID & "' AND GridID = '" & GridID & "'"
            dv.RowStateFilter = DataViewRowState.CurrentRows
            oboundCol = New BoundField
            If dv.Count > 0 Then
    
    
    
                oboundCol.DataField = DataGrid.Columns(ColCount).ColumnName.ToString
                oTemp = New Object
                oTemp = oboundCol
                oTemp.HeaderText = dv.Item(0).Row.Item("Name")
                oTemp.ItemStyle.HorizontalAlign = HorizontalAlign.Left
            Else
                oboundCol.DataField = DataGrid.Columns(ColCount).ColumnName.ToString
                oTemp = oboundCol
            End If
            Grid.Columns.Add(oTemp)
            ColCount = ColCount + 1
        End While
    
        Grid.DataSource = DataGrid
        Grid.DataBind()
    
        Return Grid
    End Function
    
    1 Reply Last reply
    0
    Reply
    • Reply as topic
    Log in to reply
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes


    • Login

    • Don't have an account? Register

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • World
    • Users
    • Groups