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

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

  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. 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. John Saunders
    Replies:
    0
    Views:
    489
    John Saunders
    Aug 28, 2003
  2. Nehmo Sergheyev
    Replies:
    1
    Views:
    523
    Andrew Urquhart
    May 9, 2004
  3. Marcin Vorbrodt

    ::std sometimes needed, sometimes not

    Marcin Vorbrodt, Sep 16, 2003, in forum: C++
    Replies:
    24
    Views:
    801
    Jerry Coffin
    Sep 17, 2003
  4. Mr. SweatyFinger
    Replies:
    2
    Views:
    2,222
    Smokey Grindel
    Dec 2, 2006
  5. Randy Smith
    Replies:
    2
    Views:
    478
    Randy Smith
    Apr 24, 2007
Loading...

Share This Page