Re: datalist formatting

Discussion in 'ASP .Net' started by Davide Vernole [MVP], Sep 7, 2004.

  1. IGotYourDotNet <> typed:
    > I have a label inside of a datalist and i need to have it visible =
    > true for one scenario, right now its shows for everything but i don't
    > want that. I need it to show for only 1 thing.
    >
    > I tried this in the datalist_ItemDataBound
    > if sType = "Cars" then
    > lblType.visible = true
    > else
    > lblType.visible = false
    > end if
    >
    > and that won't work, it's not recognizing the lblType control in the
    > datalist.


    In the method delegate for the ItemDataBound event try this:

    //Label in the header
    if((e.Item.ItemType == ListItemType.Header))
    {
    Label label = (Label)e.Item.FindControl("lblType");
    if(sType == "Cars")
    label.Visible = true;
    else
    label.Visible = false;
    }

    //Label in a item

    if((e.Item.ItemType == ListItemType.Item) || (e.Item.ItemType ==
    ListItemType.AlternatingItem))
    {
    Label label = (Label)e.Item.FindControl("lblType");
    if(sType == "Cars")
    label.Visible = true;
    else
    label.Visible = false;
    }

    --
    Davide Vernole
    MVP ASP/ASP.NET
    Microsoft Certified Solution Developer
    Davide Vernole [MVP], Sep 7, 2004
    #1
    1. Advertising

  2. IGotYourDotNet <> typed:
    > thanks that worked. One more question,
    > how can I change the value?
    >
    > example:
    > if lblType.text = "0" then
    > lblType.text = " "
    > end if
    >
    > i did this also in the Itemdatabound and nothing.
    >
    > is there anywhere online that has some datalist examples and what you
    > can and can't do with the datalist control?


    Try this:

    if((e.Item.ItemType == ListItemType.Item) || (e.Item.ItemType ==
    ListItemType.AlternatingItem))
    {
    Label label = (Label)e.Item.FindControl("lblType");
    if((DataRowView)e.Item.DataItem).Row["ColumnName"].ToString() ==
    "0")
    label.Text = string.Empty;
    }

    where ColumnName is the name of the Data source colum that it contains the
    value you want to test.

    For a quick tutorial on DataList WebControl see here:
    http://www.dotnetjunkies.com/QuickS...ms/ctrlref/webctrl/datalist/doc_datalist.aspx

    See also this link:
    http://msdn.microsoft.com/library/d...fSystemWebUIWebControlsDataListClassTopic.asp

    --
    Davide Vernole
    MVP ASP/ASP.NET
    Microsoft Certified Solution Developer
    Davide Vernole [MVP], Sep 7, 2004
    #2
    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. Joe
    Replies:
    3
    Views:
    457
  2. Leo Duran
    Replies:
    2
    Views:
    3,434
  3. Moe Sizlak

    formatting the display of a datalist?

    Moe Sizlak, Aug 2, 2004, in forum: ASP .Net
    Replies:
    2
    Views:
    495
    Moe Sizlak
    Aug 2, 2004
  4. Nevyn Twyll
    Replies:
    8
    Views:
    1,848
  5. =?Utf-8?B?RGFu?=

    Formatting date of bound data in datalist

    =?Utf-8?B?RGFu?=, Sep 16, 2004, in forum: ASP .Net
    Replies:
    0
    Views:
    319
    =?Utf-8?B?RGFu?=
    Sep 16, 2004
Loading...

Share This Page