RadListView Conditional Formatting

3 posts, 0 answers
  1. Curt
    Curt avatar
    27 posts
    Member since:
    Jan 2011

    Posted 07 Apr 2011 Link to this post

    Hello,

    I have a listview that has shows a startdate enddate starttime endtime. I want to have it only display startdate unless the enddate is not equal to the startdate. For example is the row had a startdate & enddata that were the same I would like for the enddate to be set as visable = false. I have tried the code below but cant seem to get it to work, any help would be great.

    Thanks

    <ItemTemplate>
               <li class="rlvI"> <asp:Label ID="SubjectLabel" runat="server" Text='<%# Eval("Subject") %>' />
                    <asp:Label ID="DescriptionLabel" runat="server" Text='<%# Eval("Description") %>' />
                    <asp:Label ID="StartDateLabel" runat="server" Text='<%# Eval("StartDate", "{0:MMMM dd}") %>' />
                    <asp:Label ID="EndDateLabel" runat="server" Text='<%# Eval("EndDate", "{0:MMMM dd}") %>' />
                    <asp:Label ID="StartTimeLabel" runat="server" Text='<%# Eval("StartTime","{0:t}") %>' />
                    <asp:Label ID="EndTimeLabel" runat="server" Text='<%# Eval("EndTime","{0:t}") %>' />
               </li>
           </ItemTemplate>
        protected void RadListView1_ItemDataBound(object sender, Telerik.Web.UI.RadListViewItemEventArgs e)
        {
            if (e.Item is ListViewDataItem)
            {
                ListViewDataItem item = e.Item as ListViewDataItem;
                int lbstart = (int)DataBinder.Eval(item.DataItem, "StartDateLabel");
                int lbend = (int)DataBinder.Eval(item.DataItem, "EndDateLabel");


                if (lbstart == lbend)
                {
                    item.Visible = false;
                }
            }

  2. Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 11 Apr 2011 Link to this post

    Hello Curt,

    Try the following approach to access the RadListViewItem.
     RadListViewDataItem item = e.Item as RadListViewDataItem;

    C#:
    protected void rlv_ItemDataBound(object sender, RadListViewItemEventArgs e)
       {
           if (e.Item is RadListViewDataItem)
           {
               RadListViewDataItem item = e.Item as RadListViewDataItem;
               int lbstart = (int)DataBinder.Eval(item.DataItem, "EmployeeID");
               int lbend = (int)DataBinder.Eval(item.DataItem, "EndDateLabel");
               if (lbstart == lbend)
               {
                  item.Visible = false;
               }
           }
       }

    Thanks,
    Princy.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Curt
    Curt avatar
    27 posts
    Member since:
    Jan 2011

    Posted 11 Apr 2011 Link to this post

    Thanks for the reply,

    Here is the final code that worked for me:

        protected void RadListView1_ItemDataBound(object sender, Telerik.Web.UI.RadListViewItemEventArgs e)
        {
            if (e.Item is RadListViewDataItem)
            {
                RadListViewDataItem item = e.Item as RadListViewDataItem;
                DateTime lbstart = (DateTime)DataBinder.Eval(item.DataItem, "StartDate");
                DateTime lbend = (DateTime)DataBinder.Eval(item.DataItem, "EndDate");
                if (lbstart.ToShortDateString() == lbend.ToShortDateString())
                {
                    item.FindControl("EndDateLabel").Visible = false;
                }
            }
        }
Back to Top