简体   繁体   中英

how do i loop through each readlistviewitem, check the value, and set it to bold?

I have a listview that is loaded with a list of objects that contain an attribute called AssigneeView which holds the date that the entry was opened. The listview's ItemTemplate has a label named "lblHeader". What I want to do is loop through the ListView .Items and check each element's AssigneeView attribute, if it is null , I want to set the lblHeader.Text to be bold (indicating it is unread).

I want to create a method that takes an attribute from the Object in the Items list called ticketID and lookup whether or not the AssigneeView field is null for that field and return a bool . So it would look something like

ForEach item in listview.Items
   if(IsUnread(item.datamember.ticketID)) then
       item.lblHeader.MakeBold
   else
      item.lblHeader.MakeNotBold

I'm not 100% on how to dig into the telerik control to get what I need to do this. Any suggestions?

UPDATE: here's where I am at the moment:

using (var client = new QUTIService.QSVCClient())
            {
                var data = client.SearchTickets(this.myGuid, txtSearchString.Text, 100, chkSearchClosed.Checked).ToList();
                lsvResultTickets.DataSource = data;
                lsvResultTickets.DataBind();
                if (data.Count == 0)
                {
                    lblStatus.Text = "No tickets found.";
                }
                else
                {
                    foreach (var item in lsvResultTickets.Items)
                    {
                        var obj = item.DataItem as QT.FullTicket;
                        if (TicketIsUnread(obj.OriginalTicket.TicketID))
                        {
                            //???
                        }
                    }
                }
            }

What you will need to do is check AssigneeView in the RowDataBound event and then set lblHeader accordingly. RowDataBound is called for each row in you datasource as it is added to the GridView.

if (e.Row.RowType == DataControlRowType.DataRow) {
    if (DataBinder.Eval(e.Row.DataItem, "AssigneeView") == null) {
      //Set bold
    } else {
      //Set normal
    } 
}

Ok, it turns out that I just had to drill down one more level. I didn't need to pull out another method to do the check for me. I handled this is in the item loaded event handler, here's what I ended up with:

protected void ResultItem_DataBound(object sender, RadListViewItemEventArgs e)
    {        
        var dItem = e.Item as RadListViewDataItem;
        var dObj = dItem.DataItem as QT.FullTicket;
        //if no read date, mark as unread (bold)
        if (dObj.AssigneeView == null)
        {            
            var headerLabel = e.Item.FindControl("lblHeader") as Label;
            headerLabel.Style.Add("Font-Weight", "Bold");
            headerLabel.Style.Add("Color", "Orange");
        }
    }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM