college_amy Posted August 8, 2005 Posted August 8, 2005 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..... Quote
wayneph Posted August 11, 2005 Posted August 11, 2005 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 ... Quote wayne The Road Goes on Forever and the Party Never Ends - Robert Earl Keen
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.