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. Web Development
  3. ASP.NET
  4. datagrid population

datagrid population

Scheduled Pinned Locked Moved ASP.NET
htmldatabasehelptutorial
2 Posts 2 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.
  • N Offline
    N Offline
    neoms21
    wrote on last edited by
    #1

    Hi , I need to display the records of a database in a table format on html page. so that data has to be bound on datagrid.but each column of the table to be displayed on html page comes from a different table from the database. plase help me out in this regard that how to display different columns from different tables onto that page. thanking you in anticipation neoms21

    W 1 Reply Last reply
    0
    • N neoms21

      Hi , I need to display the records of a database in a table format on html page. so that data has to be bound on datagrid.but each column of the table to be displayed on html page comes from a different table from the database. plase help me out in this regard that how to display different columns from different tables onto that page. thanking you in anticipation neoms21

      W Offline
      W Offline
      Wilbur J Pereira
      wrote on last edited by
      #2

      You would have to create a custonm template class which would be as follows Public Class CustomTemplate Implements ITemplate Private _strWhichTemplate As String Private _intChkprocessId As Int32 Public Sub New(ByVal strTemplate As String, ByVal chkValue As String) _strWhichTemplate = strTemplate _intChkprocessId = chkValue End Sub Public Sub InstantiateIn(ByVal container As Control) Implements ITemplate.InstantiateIn Select Case _strWhichTemplate.ToLower() Case "itemtemplate" Dim cb As CheckBox = New CheckBox 'Create an event handler. cb.ID = _intChkprocessId AddHandler cb.DataBinding, AddressOf Me.CheckBoxDataBinding container.Controls.Add(cb) End Select End Sub Public Sub CheckBoxDataBinding(ByVal sender As Object, ByVal e As EventArgs) 'Get the control that is being data bound. Dim cb As CheckBox = CType(sender, Object) 'Get the NamingContainer of the control. Dim iContainer As INamingContainer = CType(cb.NamingContainer, Control) 'Cast the container to an ObjectListItem. Dim item As DataGridItem = CType(iContainer, DataGridItem) 'Use the ObjectList.DataItem property to get the data. Dim dataObject As Object = CType(item.DataItem, Object) 'Place the value into the TextBox. 'tb.Text = dataObject End Sub End Class While sqlDrdr.Read Dim myCol As New TemplateColumn Dim myChk As New CheckBox 'myCol.ItemStyle.BackColor = Color.WhiteSmoke myCol.HeaderStyle.CssClass = "commontd" myCol.HeaderStyle.Font.Bold = True myCol.ItemStyle.CssClass = "Commontablebg" myCol.ItemTemplate = New CustomTemplate("itemtemplate", sqlDrdr(0)) myCol.ItemStyle.HorizontalAlign = HorizontalAlign.Center myCol.HeaderText = sqlDrdr(2) dgrCommonDocs.Columns.Add(myCol) End While dgrCommonDocs.DataBind() this way u can add as many columns as u need along with the functionality i.e diff columns in a datagrid populated with data from different tables. Regards Wilbur J. Pereira "If they love me let them, for the heck of it.If they don't, who da heck cares about it"

      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