multiple datafields in a datagrid column

Results 1 to 2 of 2

Thread: multiple datafields in a datagrid column

  1. #1
    Join Date
    Dec 1969

    Default multiple datafields in a datagrid column

    Hi,<BR><BR>I&#039;m trying to format the data in a datagrid to display in a "one box fits all" format instead of the traditional grid, and I can&#039;t work out how to do it.<BR><BR>What I want is for each row in the database, a bordered box to appear containing all the information from that row layed out within the box, whereas the traditional datagrid seems to want to appear only as a "row for a row" if that makes sense.

  2. #2
    Join Date
    Dec 1969

    Default RE: multiple datafields in a datagrid column

    hmmm... there are a couple of different approaches you can take here. <BR><BR>1. You can add bound columns and set the visibility property to false and also create a template column. Then you use the ItemDataBound property in the code behind to create your variables and concatenate the inforamtion to write to the temp column... <BR><BR>In HTML View:<BR>&#060;asp:BoundColumn Visible="False" DataField="fieldname"&#062; &#060;/asp:BoundColumn&#062;<BR>&#060;asp:TemplateColumn HeaderText="Additional Information"&#062;<BR>&#060;ItemStyle&#062;&#060;/ItemStyle&#062;<BR>&#060;/asp:TemplateColumn&#062;<BR><BR>In the code behind you would call the ItemDataBound on your datagrid. Example:<BR> Private Sub DataGrid_ItemDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DataGridItemEventArgs) Handles DataGrid_Acc.ItemDataBound<BR> <BR>Dim itemType As ListItemType<BR>itemType = CType(e.Item.ItemType, ListItemType)<BR>&#039;Set myfield to the value of the field you have in the bound column. Columns start at 0<BR>dim myfield as fieldname<BR>myfield = e.Item.Cells(0).Text.ToString<BR><BR>&#039;Set the information to your template column<BR>e.Item.Cells(1).Text = myfield<BR><BR>2. You can use a datarepeater in order to do your own formatting. The downside is there is no built in paging.<BR><BR>I hope this helps!<BR><BR>JM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts