Filtering data and adding headers within same datagrid

Ask a Question related to ASP.NET Data Grid Control, Design and Development.

  1. #1

    Default Filtering data and adding headers within same datagrid

    Hello,

    Posted this over on the ADO.net group but it belongs here.

    I am working on a ASP page with a datagrid that has 5 columns that I bind
    to
    a datatable which is filled via the ReadXml parser.
    Once this data is there I need a way to:
    1) Segregate each unique group of data that has the same value in one of
    the
    fields.
    (ie DataRow dr["col1"] = 'A' - A data, DataRow dr["col1"] = 'B' - B
    data, etc )

    For the A data the data grid would have headers H1, H2, H3, H4, H5
    data: d1
    d2 d3 d4 d5
    For the B data the data grid would have H1,
    H5

    d1 d5
    Something different for C data H1, H3,
    H5

    d1 d3 d5

    This must occur within the same datagrid D1.
    I have figured out how to get the unique headers into the datagrid by
    checking the data from the dataset but getting that
    special label row in the right place along with its associated data escapes
    me.

    2) Ensure that I capture the first instance of B data in col1 and insert
    that label row into the grid.

    I have already used unique datagrid for each set of data but that wasn't
    pretty enough for the customer because the columns didn't
    line up from one grid to the next.

    Any Help is appreciated,
    Trez

    PS. Using C#




    Tr Guest

  2. Similar Questions and Discussions

    1. adding sub group headers dynamically for datagrid in prerender
      problem.. the code creates a header row when i see the rendered hTML but it is not creating the table cell inside the row. ie. it is rendering as...
    2. Filtering data in a Datagrid
      Hi, I'm viewing the thread and found that there is a duplicated one on this issue in microsoft.public.dotnet.framework.aspnet group and some...
    3. DataGrid - Adding labels: and adding data to cells
      I am just getting started with flash scripting. My downfall is trying to get the dynamic output to display in flash. I tried using the list...
    4. filtering in datagrid
      Hi, I need to include the filtering feature in datagrid just like in excel sheet where user can filter the rows based on the value selected in the...
    5. Adding textboxes for filtering in DataGrid header
      Hi All, - Visual Studio 2002 - VB.NET > ASP.NET I created a DataGrid on a webform. This datagrid has sorting enabled. I want to create in the...
  3. #2

    Default Re: Filtering data and adding headers within same datagrid


    Hi,

    I have done this several times recently, and it works pretty well. Here is
    the code i use. I picked it up from some site, and then just adapted it to
    our projects. It is VB though. Most of it shouldnt be too hard to convert to
    C#, but there are a few keywords and things i wasnt sure of so i figured id
    leave that for someone who is more familiar with C# rather than messing it
    up by accident.

    HTH.

    Private Sub grdHours_ItemCreated(ByVal sender As Object, ByVal e As
    System.Web.UI.WebControls.DataGridItemEventArgs) Handles
    grdHours.ItemCreated
    Dim i As DataGridItem = e.Item
    Static lastproject As String

    Select Case i.ItemType
    Case ListItemType.Header
    lastproject = ""
    Case ListItemType.Item, ListItemType.AlternatingItem
    Dim curproject As String, curprojectnum As String
    If Binding Then
    Dim dr As DataRow = CType(i.DataItem, DataRowView).Row
    curproject = dr("PROJECT")
    curprojectnum = dr("PROJECTNUM")
    Else
    curproject = i.Cells(10).Text
    curprojectnum = i.Cells(11).Text
    End If

    If curproject <> lastproject Then
    Dim grd As DataGrid = sender
    Dim c As TableCell, di As DataGridItem

    c = New TableCell
    With c
    .ColumnSpan = grd.Columns.Count
    .BackColor = ColorTranslator.FromHtml("#B0C4DE")
    .ForeColor = ColorTranslator.FromHtml("#553E13")
    .Font.Bold = True
    .Style.Add("FONT-VARIANT", "SMALL-CAPS")
    .Style.Add("PADDING-LEFT", "3px")
    .Style.Add("BORDER-RIGHT", "#A5A6A5 1px solid")
    .Style.Add("BORDER-BOTTOM", "#A5A6A5 2px solid")

    .Text = curproject & " [<label style='color: Navy'>"
    & curprojectnum & "</label>]"
    .Text &= " - <label style='font-weight: normal;
    font-size: 8pt; color: black; font-variant: normal;'>" &
    CStr(NVL(dbObj.ExecuteScalar("SELECT PROJECT_DESC1 FROM PROJECTS WHERE
    PROJECT_NO = " & curprojectnum), "")).ToLower & "</label>"
    End With
    di = New DataGridItem(i.ItemIndex + 1, 0,
    ListItemType.Item)
    di.Cells.Add(c)
    CType(grd.Controls(0), Table).Rows.Add(di)

    lastproject = curproject
    End If
    End Select
    End Sub


    Eidolon Guest

Posting Permissions

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

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139