469,621 Members | 1,853 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,621 developers. It's quick & easy.

Datagrid set field item to disply only when new

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.

Nov 19 '05 #1
4 1373
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

"Kurt Schroeder" wrote:
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.

Nov 19 '05 #2
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}&t ypmainIDX="
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>
</asp:DataGrid></TD>
"Ian Suttle" wrote:
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

"Kurt Schroeder" wrote:
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.

Nov 19 '05 #3
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

"Kurt Schroeder" wrote:
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}&t ypmainIDX="
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>
</asp:DataGrid></TD>
"Ian Suttle" wrote:
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

"Kurt Schroeder" wrote:
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.

Nov 19 '05 #4
thanks!!
kes

"Ian Suttle" wrote:
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

"Kurt Schroeder" wrote:
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}&t ypmainIDX="
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>
</asp:DataGrid></TD>
"Ian Suttle" wrote:
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

"Kurt Schroeder" wrote:

> 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.
>

Nov 19 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by Jim Heavey | last post: by
1 post views Thread by Jeremy | last post: by
1 post views Thread by Harry Devine | last post: by
5 posts views Thread by junglist | last post: by
reply views Thread by Nathan Franklin | last post: by
reply views Thread by cms3023 | last post: by
reply views Thread by gheharukoh7 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.