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

Alessandro Zifiglio

That piece of code you pasted should work well. Your code also eliminates
the header row.

Look for the problem some place else. If you still cannot resolve, paste the
rest of the code you have.
Regards,
Alessandro Zifiglio
http://www.AsyncUI.net
 
A

Alessandro Zifiglio

also, unless your datasource is not returning any rows, in which case only
the header row will show. This is logical ofcourse =P

Regards,
Alessandro Zifiglio
http://www.AsyncUI.net

Alessandro Zifiglio said:
That piece of code you pasted should work well. Your code also eliminates
the header row.

Look for the problem some place else. If you still cannot resolve, paste
the rest of the code you have.
Regards,
Alessandro Zifiglio
http://www.AsyncUI.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

The datasource returns many rows. On testing, the itemDataBind fires
only once and e.Item.ItemType.TString() return 'header'


Alessandro said:
also, unless your datasource is not returning any rows, in which case only
the header row will show. This is logical ofcourse =P

Regards,
Alessandro Zifiglio
http://www.AsyncUI.net

Alessandro Zifiglio said:
That piece of code you pasted should work well. Your code also eliminates
the header row.

Look for the problem some place else. If you still cannot resolve, paste
the rest of the code you have.
Regards,
Alessandro Zifiglio
http://www.AsyncUI.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?
Barbra
The datasource returns many rows. On testing, the itemDataBind fires
only once and e.Item.ItemType.TString() return 'header'


Alessandro said:
also, unless your datasource is not returning any rows, in which case only
the header row will show. This is logical ofcourse =P

Regards,
Alessandro Zifiglio
http://www.AsyncUI.net

Alessandro Zifiglio said:
That piece of code you pasted should work well. Your code also eliminates
the header row.

Look for the problem some place else. If you still cannot resolve, paste
the rest of the code you have.
Regards,
Alessandro Zifiglio
http://www.AsyncUI.net

<[email protected]> ha scritto nel messaggio
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?
Barbra
The datasource returns many rows. On testing, the itemDataBind fires
only once and e.Item.ItemType.TString() return 'header'


Alessandro said:
also, unless your datasource is not returning any rows, in which case only
the header row will show. This is logical ofcourse =P

Regards,
Alessandro Zifiglio
http://www.AsyncUI.net

"Alessandro Zifiglio" <AlessandroZifiglio @ -h-o-t-m-a-i-l-c-o-m> ha scritto
nel messaggio That piece of code you pasted should work well. Your code also eliminates
the header row.

Look for the problem some place else. If you still cannot resolve, paste
the rest of the code you have.
Regards,
Alessandro Zifiglio
http://www.AsyncUI.net

<[email protected]> ha scritto nel messaggio
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.
 
A

Alessandro Zifiglio

glad you resolved the issue.
have a good day,

Alessandro Zifiglio
http://www.AsyncUI.net


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?
Barbra
The datasource returns many rows. On testing, the itemDataBind fires
only once and e.Item.ItemType.TString() return 'header'


Alessandro Zifiglio wrote:
also, unless your datasource is not returning any rows, in which case
only
the header row will show. This is logical ofcourse =P

Regards,
Alessandro Zifiglio
http://www.AsyncUI.net

"Alessandro Zifiglio" <AlessandroZifiglio @ -h-o-t-m-a-i-l-c-o-m> ha
scritto
nel messaggio That piece of code you pasted should work well. Your code also
eliminates
the header row.

Look for the problem some place else. If you still cannot resolve,
paste
the rest of the code you have.
Regards,
Alessandro Zifiglio
http://www.AsyncUI.net

<[email protected]> ha scritto nel messaggio
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

No members online now.

Forum statistics

Threads
474,432
Messages
2,571,680
Members
48,796
Latest member
Greg L.

Latest Threads

Top