ItemDataBound fires for header only

B

bkasmai

This is driving me crazy. I need to hide rows that a particular cell is
zero. On debuggng I fiound out that ItemDataBound fires for header only
and not for Item and AlternatingItem
private void grdSelectionList_ItemDataBound(object sender,
System.Web.UI.WebControls.DataGridItemEventArgs e)
{
if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType ==
ListItemType.AlternatingItem )
{
if (e.Item.Cells[2].Text == "0")
{
e.Item.Visible = false;
}
}

Any help on this will be appreciated.
 
B

bkasmai

I have. All items are listed and all rows are displayed ok. I have
checked the data type. e.Item.ItemType.ToString() returns 'header'.
BK
Eliyahu said:
First make sure you have any data items to bind to. Then set a breakpoint on
your type checking statement and check the value of e.Item.ItemType.
--
Eliyahu Goldin,
Software Developer & Consultant
Microsoft MVP [ASP.NET]

This is driving me crazy. I need to hide rows that a particular cell is
zero. On debuggng I fiound out that ItemDataBound fires for header only
and not for Item and AlternatingItem
private void grdSelectionList_ItemDataBound(object sender,
System.Web.UI.WebControls.DataGridItemEventArgs e)
{
if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType ==
ListItemType.AlternatingItem )
{
if (e.Item.Cells[2].Text == "0")
{
e.Item.Visible = false;
}
}

Any help on this will be appreciated.
 
E

Eliyahu Goldin

First make sure you have any data items to bind to. Then set a breakpoint on
your type checking statement and check the value of e.Item.ItemType.
 
B

bkasmai

Correct! It is get called only once with the itemtype Header and no any
other call for data rows.

Eliyahu said:
You mean the event handler gets called first with the itemtype Header and
then doesn't get called for the data items?
--
Eliyahu Goldin,
Software Developer & Consultant
Microsoft MVP [ASP.NET]

I have. All items are listed and all rows are displayed ok. I have
checked the data type. e.Item.ItemType.ToString() returns 'header'.
BK
Eliyahu said:
First make sure you have any data items to bind to. Then set a breakpoint
on
your type checking statement and check the value of e.Item.ItemType.
--
Eliyahu Goldin,
Software Developer & Consultant
Microsoft MVP [ASP.NET]

This is driving me crazy. I need to hide rows that a particular cell is
zero. On debuggng I fiound out that ItemDataBound fires for header only
and not for Item and AlternatingItem
private void grdSelectionList_ItemDataBound(object sender,
System.Web.UI.WebControls.DataGridItemEventArgs e)
{
if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType ==
ListItemType.AlternatingItem )
{
if (e.Item.Cells[2].Text == "0")
{
e.Item.Visible = false;
}
}

Any help on this will be appreciated.
 
E

Eliyahu Goldin

You mean the event handler gets called first with the itemtype Header and
then doesn't get called for the data items?
--
Eliyahu Goldin,
Software Developer & Consultant
Microsoft MVP [ASP.NET]

I have. All items are listed and all rows are displayed ok. I have
checked the data type. e.Item.ItemType.ToString() returns 'header'.
BK
Eliyahu said:
First make sure you have any data items to bind to. Then set a breakpoint
on
your type checking statement and check the value of e.Item.ItemType.
--
Eliyahu Goldin,
Software Developer & Consultant
Microsoft MVP [ASP.NET]

This is driving me crazy. I need to hide rows that a particular cell is
zero. On debuggng I fiound out that ItemDataBound fires for header only
and not for Item and AlternatingItem
private void grdSelectionList_ItemDataBound(object sender,
System.Web.UI.WebControls.DataGridItemEventArgs e)
{
if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType ==
ListItemType.AlternatingItem )
{
if (e.Item.Cells[2].Text == "0")
{
e.Item.Visible = false;
}
}

Any help on this will be appreciated.
 
B

bkasmai

I now know the cause of the problem but not the solution. The column 2
is a TemplateColumn populated with data but e.Item.Cells[2].Text
returns empty string. All other cells which are databond return correct
values. This seems to be a fundamental misunderstandig on my behalf.
Any idea how can I solve this?

Eliyahu said:
Do you handle any other events that can effect data items? Like ItemCreated?
--
Eliyahu Goldin,
Software Developer & Consultant
Microsoft MVP [ASP.NET]

Correct! It is get called only once with the itemtype Header and no any
other call for data rows.

Eliyahu said:
You mean the event handler gets called first with the itemtype Header and
then doesn't get called for the data items?
--
Eliyahu Goldin,
Software Developer & Consultant
Microsoft MVP [ASP.NET]

I have. All items are listed and all rows are displayed ok. I have
checked the data type. e.Item.ItemType.ToString() returns 'header'.
BK
Eliyahu Goldin wrote:
First make sure you have any data items to bind to. Then set a
breakpoint
on
your type checking statement and check the value of e.Item.ItemType.
--
Eliyahu Goldin,
Software Developer & Consultant
Microsoft MVP [ASP.NET]

This is driving me crazy. I need to hide rows that a particular cell
is
zero. On debuggng I fiound out that ItemDataBound fires for header
only
and not for Item and AlternatingItem
private void grdSelectionList_ItemDataBound(object sender,
System.Web.UI.WebControls.DataGridItemEventArgs e)
{
if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType ==
ListItemType.AlternatingItem )
{
if (e.Item.Cells[2].Text == "0")
{
e.Item.Visible = false;
}
}

Any help on this will be appreciated.
 
B

bkasmai

Found the solution! For TemplateColumn the FindControl must be used:

Label lbl = (Label)e.Item.Cells[2].FindControl("label_ID");
if (lbl.Text == "0")
{
e.Item.Visible = false;
}
I now know the cause of the problem but not the solution. The column 2
is a TemplateColumn populated with data but e.Item.Cells[2].Text
returns empty string. All other cells which are databond return correct
values. This seems to be a fundamental misunderstandig on my behalf.
Any idea how can I solve this?

Eliyahu said:
Do you handle any other events that can effect data items? Like ItemCreated?
--
Eliyahu Goldin,
Software Developer & Consultant
Microsoft MVP [ASP.NET]

Correct! It is get called only once with the itemtype Header and no any
other call for data rows.

Eliyahu Goldin wrote:
You mean the event handler gets called first with the itemtype Header and
then doesn't get called for the data items?
--
Eliyahu Goldin,
Software Developer & Consultant
Microsoft MVP [ASP.NET]

I have. All items are listed and all rows are displayed ok. I have
checked the data type. e.Item.ItemType.ToString() returns 'header'.
BK
Eliyahu Goldin wrote:
First make sure you have any data items to bind to. Then set a
breakpoint
on
your type checking statement and check the value of e.Item.ItemType.
--
Eliyahu Goldin,
Software Developer & Consultant
Microsoft MVP [ASP.NET]

This is driving me crazy. I need to hide rows that a particular cell
is
zero. On debuggng I fiound out that ItemDataBound fires for header
only
and not for Item and AlternatingItem
private void grdSelectionList_ItemDataBound(object sender,
System.Web.UI.WebControls.DataGridItemEventArgs e)
{
if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType ==
ListItemType.AlternatingItem )
{
if (e.Item.Cells[2].Text == "0")
{
e.Item.Visible = false;
}
}

Any help on this will be appreciated.
 
E

Eliyahu Goldin

Do you handle any other events that can effect data items? Like ItemCreated?
--
Eliyahu Goldin,
Software Developer & Consultant
Microsoft MVP [ASP.NET]

Correct! It is get called only once with the itemtype Header and no any
other call for data rows.

Eliyahu said:
You mean the event handler gets called first with the itemtype Header and
then doesn't get called for the data items?
--
Eliyahu Goldin,
Software Developer & Consultant
Microsoft MVP [ASP.NET]

I have. All items are listed and all rows are displayed ok. I have
checked the data type. e.Item.ItemType.ToString() returns 'header'.
BK
Eliyahu Goldin wrote:
First make sure you have any data items to bind to. Then set a
breakpoint
on
your type checking statement and check the value of e.Item.ItemType.
--
Eliyahu Goldin,
Software Developer & Consultant
Microsoft MVP [ASP.NET]

This is driving me crazy. I need to hide rows that a particular cell
is
zero. On debuggng I fiound out that ItemDataBound fires for header
only
and not for Item and AlternatingItem
private void grdSelectionList_ItemDataBound(object sender,
System.Web.UI.WebControls.DataGridItemEventArgs e)
{
if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType ==
ListItemType.AlternatingItem )
{
if (e.Item.Cells[2].Text == "0")
{
e.Item.Visible = false;
}
}

Any help on this will be appreciated.
 

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

Forum statistics

Threads
473,995
Messages
2,570,230
Members
46,818
Latest member
Brigette36

Latest Threads

Top