This is a migrated thread and some comments may be shown as answers.

RadListView Conditional Formatting

2 Answers 222 Views
ListView
This is a migrated thread and some comments may be shown as answers.
Curt
Top achievements
Rank 1
Curt asked on 07 Apr 2011, 06:06 PM

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 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 11 Apr 2011, 09:29 AM
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.
0
Curt
Top achievements
Rank 1
answered on 11 Apr 2011, 09:48 PM
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;
            }
        }
    }
Tags
ListView
Asked by
Curt
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Curt
Top achievements
Rank 1
Share this question
or