Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP .Net Datagrid Control > ItemDataBound fires for header only

Reply
Thread Tools

ItemDataBound fires for header only

 
 
bkasmai@gmail.com
Guest
Posts: n/a
 
      07-23-2006
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.

 
Reply With Quote
 
 
 
 
bkasmai@gmail.com
Guest
Posts: n/a
 
      07-23-2006
I now know the cause of this 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?

http://www.velocityreviews.com/forums/(E-Mail Removed) wrote:
> 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.


 
Reply With Quote
 
 
 
 
bkasmai@gmail.com
Guest
Posts: n/a
 
      07-23-2006
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;
}

(E-Mail Removed) wrote:
> I now know the cause of this 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?
>
> (E-Mail Removed) wrote:
> > 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.


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Simple composite control fires event fires first time but not second sellars.paul@googlemail.com ASP .Net Web Controls 3 05-13-2009 03:19 PM
ItemDataBound fires for header only bkasmai@gmail.com ASP .Net Web Controls 6 07-23-2006 11:42 AM
ItemDataBound fires for header only bkasmai@gmail.com ASP .Net 7 07-23-2006 11:01 AM
Itemdatabound event fires once for Datagrid header only and NOT for data rows bkasmai@gmail.com ASP .Net Datagrid Control 0 07-23-2006 09:40 AM
Nested Repeaters: ItemDataBound fires in reverse order (hierarchical data) KJ ASP .Net 0 06-21-2005 10:11 PM



Advertisments