Why visible=false only work sometimes on datagrid?

Discussion in 'ASP .Net' started by Adam Smith, Apr 19, 2004.

  1. Adam Smith

    Adam Smith Guest

    The following code in my onitemcreated works for some item rows in my
    datagrid, but not others. I am trying to set a linkbutton visible for
    downloading a file if the data is available in the database, otherwise
    set a "not available" label visible. The outcome is that for the first
    row on my datagrid, the linkbutton is visible, for the second row both
    the linkbutton *and* the label are visible and for the third row, again
    only the linkbutton is visible:

    private void OnItemCreated(object sender,
    System.Web.UI.WebControls.DataGridItemEventArgs e)
    {
    if(e.Item.ItemType == ListItemType.Item)
    {
    if(DataBinder.Eval(e.Item.DataItem,"RESULT") == DBNull.Value)
    ((LinkButton)e.Item.Cells[10].FindControl("lbtnDownload")).Visible =
    false;
    else
    ((Label)e.Item.Cells[10].FindControl("lblNotAvailable")).Visible =
    false;
    }
    }

    Thanks in advance.

    Adam Smith

    *** Sent via Developersdex http://www.developersdex.com ***
    Don't just participate in USENET...get rewarded for it!
     
    Adam Smith, Apr 19, 2004
    #1
    1. Advertisements

  2. Your code is executing for all ListItemType.Item types ... you have to also
    include the ListItemType.AlternatingItem type!

    Thanks,
    - jeff

    "Adam Smith" <> wrote in message
    news:...
    > The following code in my onitemcreated works for some item rows in my
    > datagrid, but not others. I am trying to set a linkbutton visible for
    > downloading a file if the data is available in the database, otherwise
    > set a "not available" label visible. The outcome is that for the first
    > row on my datagrid, the linkbutton is visible, for the second row both
    > the linkbutton *and* the label are visible and for the third row, again
    > only the linkbutton is visible:
    >
    > private void OnItemCreated(object sender,
    > System.Web.UI.WebControls.DataGridItemEventArgs e)
    > {
    > if(e.Item.ItemType == ListItemType.Item)
    > {
    > if(DataBinder.Eval(e.Item.DataItem,"RESULT") == DBNull.Value)
    > ((LinkButton)e.Item.Cells[10].FindControl("lbtnDownload")).Visible =
    > false;
    > else
    > ((Label)e.Item.Cells[10].FindControl("lblNotAvailable")).Visible =
    > false;
    > }
    > }
    >
    > Thanks in advance.
    >
    > Adam Smith
    >
    > *** Sent via Developersdex http://www.developersdex.com ***
    > Don't just participate in USENET...get rewarded for it!
     
    Jeffrey A. Voigt, Apr 19, 2004
    #2
    1. Advertisements

  3. Adam Smith

    Matt Berther Guest

    Hello Adam,

    if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)

    > private void OnItemCreated(object sender,
    > System.Web.UI.WebControls.DataGridItemEventArgs e)
    > {


    > if(e.Item.ItemType == ListItemType.Item)
    > {
    > if(DataBinder.Eval(e.Item.DataItem,"RESULT") == DBNull.Value)
    > ((LinkButton)e.Item.Cells[10].FindControl("lbtnDownload")).Visible =
    > false;
    > else
    > ((Label)e.Item.Cells[10].FindControl("lblNotAvailable")).Visible =
    > false;
    > }
    > }


    --
    Matt Berther
    http://www.mattberther.com
     
    Matt Berther, Apr 19, 2004
    #3
  4. Adam Smith

    Adam Smith Guest

    Thanks!

    Matt Berther <> wrote in message news:<>...
    > Hello Adam,
    >
    > if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
    >
    > > private void OnItemCreated(object sender,
    > > System.Web.UI.WebControls.DataGridItemEventArgs e)
    > > {

    >
    > > if(e.Item.ItemType == ListItemType.Item)
    > > {
    > > if(DataBinder.Eval(e.Item.DataItem,"RESULT") == DBNull.Value)
    > > ((LinkButton)e.Item.Cells[10].FindControl("lbtnDownload")).Visible =
    > > false;
    > > else
    > > ((Label)e.Item.Cells[10].FindControl("lblNotAvailable")).Visible =
    > > false;
    > > }
    > > }
     
    Adam Smith, Apr 21, 2004
    #4
    1. Advertisements

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. Nehmo Sergheyev
    Replies:
    1
    Views:
    688
    Andrew Urquhart
    May 9, 2004
  2. Marcin Vorbrodt

    ::std sometimes needed, sometimes not

    Marcin Vorbrodt, Sep 16, 2003, in forum: C++
    Replies:
    24
    Views:
    1,086
    Jerry Coffin
    Sep 17, 2003
  3. Replies:
    1
    Views:
    649
    gkelly
    Nov 29, 2006
  4. Mr. SweatyFinger
    Replies:
    2
    Views:
    2,822
    Smokey Grindel
    Dec 2, 2006
  5. Randy Smith
    Replies:
    2
    Views:
    657
    Randy Smith
    Apr 24, 2007
  6. Stef Mientki
    Replies:
    0
    Views:
    313
    Stef Mientki
    Oct 18, 2008
  7. Sébastien Barthélemy

    __file__ is sometimes absolute, sometimes relative

    Sébastien Barthélemy, Oct 1, 2010, in forum: Python
    Replies:
    1
    Views:
    776
    Arnaud Delobelle
    Oct 1, 2010
  8. paul reed

    Custom Control Width sometimes has a value...sometimes doesn't

    paul reed, Feb 17, 2004, in forum: ASP .Net Building Controls
    Replies:
    8
    Views:
    332
    Jeffrey Tan[MSFT]
    Feb 21, 2004
Loading...