Datagrid set field item to disply only when new

G

Guest

I have a data grid with about 20 repeating items. they
data:
colors, red
colors,blue
colors, green
Animals cat
animals bird
people, Tom
people, Bill
people, Kris
i want to have a level break so that THe first column will show only when
the "itemtype" is different from the previous. The data output as follows

Colors Red
Blue
green
Animals cat
bird
People
Tom
Bill
Kris

I'm not sure how to check for the first data value or where to check for it.
is there an "onChange" like event when the data isbound to the column?
I will post code if required, but i think this is a beginner/beginner
question for most of you. Note: i'm using VS.net and code behind.
 
G

Guest

Kurt,

I would use the ItemDataBound event. Start off by setting a page level
variable to have an initial value of "". Then detect if the value of the
category is different than your variable. If it is, display the column value
and set the variable to the new value. If it isn't, you can set the cell
Text property to "" so that nothing shows.

Ian Suttle
http://www.IanSuttle.com
http://www.NewsFuel.com
 
G

Guest

thanks for answering.
I think that's where i need to start, but i don't know how to reference the
data item.
i can get the index of the data item but how do i get the value of a
specific field:

Private Sub DataGrid1_ItemDataBound(ByVal sender As Object, ByVal e As
System.Web.UI.WebControls.DataGridItemEventArgs) Handles
DataGrid1.ItemDataBound

lblLabel1.Text = lblLabel1.Text & ", " & e.Item.ItemIndex

End Sub

here is the data grid:

<asp:DataGrid id="DataGrid1" runat="server" PageSize="3"
EnableViewState="False" AutoGenerateColumns="False">
<Columns>
<asp:BoundColumn DataField="typmainName"
Visible="false"></asp:BoundColumn>
<asp:BoundColumn DataField="typSubName"></asp:BoundColumn>
<asp:HyperLinkColumn Text="select" HeaderText="goto"
NavigateUrl="item.aspx?itmid="></asp:HyperLinkColumn>
<asp:BoundColumn DataField="itmID" ReadOnly="True"
HeaderText="ID"></asp:BoundColumn>
<asp:BoundColumn DataField="itmDesc3" ReadOnly="True"
HeaderText="Item"></asp:BoundColumn>
<asp:HyperLinkColumn DataTextField="itmDesc3"
DataNavigateUrlField="itmID"
DataNavigateUrlFormatString="item.aspx?itmid={0}&typmainIDX="
HeaderText="item"></asp:HyperLinkColumn>
<asp:TemplateColumn HeaderText="thisone">
<ItemTemplate>
<asp:HyperLink ID="itmID" Runat="server" NavigateUrl='<%#
"item.aspx?itmID=" & Container.DataItem("itmID") & "&MNTypID=" &
Container.DataItem("typmainIDX") %>'>go</asp:HyperLink>
</ItemTemplate>
</asp:TemplateColumn>
</Columns>
 
G

Guest

Kurt,

The the function argument "e" represents
System.Web.UI.WebControls.DataGridItemEventArgs and has access to the cells
collection. Try this to get or set the text:

strThing = e.Item.Cells(indexOfCell).Text

or

e.Item.Cells(indexOfCell).Text = "A Value"

Just be sure to specify what the cell index is instead of the indexOfCell
variable here.

Ian Suttle
http://www.IanSuttle.com
http://www.NewsFuel.com
 
G

Guest

thanks!!
kes

Ian Suttle said:
Kurt,

The the function argument "e" represents
System.Web.UI.WebControls.DataGridItemEventArgs and has access to the cells
collection. Try this to get or set the text:

strThing = e.Item.Cells(indexOfCell).Text

or

e.Item.Cells(indexOfCell).Text = "A Value"

Just be sure to specify what the cell index is instead of the indexOfCell
variable here.

Ian Suttle
http://www.IanSuttle.com
http://www.NewsFuel.com
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,438
Messages
2,571,699
Members
48,796
Latest member
Greg L.
Top