datagrid population
-
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
-
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
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"