ItemDataBound fires for header only

Discussion in 'ASP .Net Web Controls' started by bkasmai@gmail.com, Jul 23, 2006.

  1. Guest

    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.
     
    , Jul 23, 2006
    #1
    1. Advertising

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

    <> ha scritto nel messaggio
    news:...
    > 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.
    >
     
    Alessandro Zifiglio, Jul 23, 2006
    #2
    1. Advertising

  3. 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 news:%23nBc%...
    > 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
    >
    > <> ha scritto nel messaggio
    > news:...
    >> 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.
    >>

    >
    >
     
    Alessandro Zifiglio, Jul 23, 2006
    #3
  4. Guest

    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 news:%23nBc%...
    > > 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
    > >
    > > <> ha scritto nel messaggio
    > > news:...
    > >> 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.
    > >>

    > >
    > >
     
    , Jul 23, 2006
    #4
  5. Guest

    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
    wrote:
    > 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 news:%23nBc%...
    > > > 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
    > > >
    > > > <> ha scritto nel messaggio
    > > > news:...
    > > >> 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.
    > > >>
    > > >
    > > >
     
    , Jul 23, 2006
    #5
  6. Guest

    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;
    }

    wrote:
    > 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
    > wrote:
    > > 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 news:%23nBc%...
    > > > > 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
    > > > >
    > > > > <> ha scritto nel messaggio
    > > > > news:...
    > > > >> 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.
    > > > >>
    > > > >
    > > > >
     
    , Jul 23, 2006
    #6
  7. glad you resolved the issue.
    have a good day,

    Alessandro Zifiglio
    http://www.AsyncUI.net


    <> ha scritto nel messaggio
    news:...
    > 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;
    > }
    >
    > wrote:
    >> 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
    >> wrote:
    >> > 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 news:%23nBc%...
    >> > > > 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
    >> > > >
    >> > > > <> ha scritto nel messaggio
    >> > > > news:...
    >> > > >> 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.
    >> > > >>
    >> > > >
    >> > > >

    >
     
    Alessandro Zifiglio, Jul 23, 2006
    #7
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. KJ
    Replies:
    0
    Views:
    2,329
  2. Replies:
    7
    Views:
    1,722
    Eliyahu Goldin
    Jul 23, 2006
  3. ItemDataBound fires for header only

    , Jul 23, 2006, in forum: ASP .Net Datagrid Control
    Replies:
    2
    Views:
    135
  4. Replies:
    0
    Views:
    237
  5. Replies:
    3
    Views:
    1,009
Loading...

Share This Page