Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

Background:

I have a datagrid that displays information from a stored procedure.

 

Problem:

In this datagrid there are numerous instances of the same "main" title (see example)

Example Datagrid:

Field1 field 2 field 3

Data1 Data2 Unique Data

Data1 Data2 Different Data

Data1 Data2 More Unique Data

 

So basically.. Field1 and Field2 have different data from themselves, but the data throughout the field is the same. What I want to do is have only the FIRST row of data where Data1 and Data2 are the same (but unique to each other) display and all the other rows beneath them where Data1 and Data2 are the same be blank.

 

How do I do that?

 

(Here is an example of the output desired)

Example Datagrid:

Field1 field 2 field 3

Data1 Data2 Unique Data

Different Data

More Unique Data

Data3 Data4 UniqueData

Different Data

MoreUniqueData

Data5 Data6 etc. etc.....

Posted

My suggestion would be to use the ItemDataBound function with some Static variables. and do something like this... (untested because I don't have time to set up a database right now)

 

Public Sub HideCells(ByVal sender As Object, _
   ByVal e As System.Web.UI.WebControls.DataGridItemEventArgs)
 Static col1Value as String
 Static col2Value as String

 Dim dr as DataRow = CType(e.Item.DataItem, DataRow)

 If e.Item.ItemType = ListItemType.AlternatingItem Or _
     e.Item.ItemType = ListItemType.Item Then
   If dr.Item("col1Name") <> col1Value Then
     e.Item.FindControl("lblCol1").visible = true
     col1Value = dr.Item("col1Name")
     e.Item.FindControl("lblCol2").visible = true
     col2Value = dr.Item("col2Name")
   ElseIf dr.Item("col2Name") <> col2Value Then
     e.Item.FindControl("lblCol1").visible = false      
     e.Item.FindControl("lblCol2").visible = true
     col2Value = dr.Item("col2Name")
   Else
     e.Item.FindControl("lblCol1").visible = false      
     e.Item.FindControl("lblCol2").visible = false      
   End If
 End If
End Sub

 

if column 1 and column two always change together, you can probably get away with just the first and last part of the conditional. This loop will handle the following situation:

Header1  Header2  Header3
asdf     qwer     1234
                 2345
        yuio     4564
                 3456
                 9876
hjkl     vbnm     7667
...

wayne

 

The Road Goes on Forever and the Party Never Ends - Robert Earl Keen

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...