OnItemDataBind RRS feed

  • Question

  • User-1607879999 posted
    Hi all, I am trying to bold my data in the OnItemDataBind event of a list. Problem is the examples I see are all object list. When I set a breakpoint and try to see the values I cannot figure out how to get the value of what is bound. Any help is appreciated. Thanks, Aaron Here is the code: <mobile:List id="lstEmail" runat="server" OnItemDataBind="lstEmail_OnItemDataBind"> <DeviceSpecific> <Choice Filter="isHTML32"> <HeaderTemplate> </HeaderTemplate> <ItemTemplate> </ItemTemplate> <FooterTemplate>
    <asp:LinkButton id="ReadEmail" Runat="server"> <%# DataBinder.Eval(((MobileListItem)Container).DataItem,"FromName") %> </asp:LinkButton> <%# DataBinder.Eval(((MobileListItem)Container).DataItem,"messagedate","{0:MM/dd/yyyy HH:mm}") %>
    <%# DataBinder.Eval(((MobileListItem)Container).DataItem,"subject") %>
    </FooterTemplate> </Choice> </DeviceSpecific> </mobile:List> codebehind: public void lstEmail_OnItemDataBind(object sender, ListDataBindEventArgs e) { }
    Sunday, July 27, 2003 12:44 PM

All replies

  • User664499748 posted
    You can try something like the following in OnPreRender to acheive the functionality you want lstEmail.EnsureTemplatedUI(); foreach(Control c1 in lstEmail.Controls) { if (((System.Web.UI.MobileControls.LinkButton) c1.FindControl("ReadMail")) != null) { if (((System.Web.UI.MobileControls.LinkButton) c1.FindControl("ReadMail")).Text == "something") ((System.Web.UI.MobileControls.LinkButton) c1.FindControl("ReadMail")).Font.Bold = System.Web.UI.MobileControls.BooleanOption.True; } } Hope that helps Kashif
    Monday, July 28, 2003 10:26 PM
  • User-1607879999 posted
    I understand what you are trying to do, before the actual control is outputted we are changing the data. I got the example working in my code, but how would I work this with a dataset. I have a dataset with unread and attachment numbers. If unread is true then I will bold everything, if attachments>0 then I will show a little icon. I don't have all my data in controls on the page... do I have to in order to do it this way. I appologize, I don't think I explained myself clearly. That is why I was attempting it in the OnDataBind method. Aaron
    Tuesday, July 29, 2003 3:43 PM
  • User-1155260916 posted
    You could try setting up the binding expression against the linkbutton directly. The templates are not created before the listItems, so the OnDataBinding handler will not be able to access the template of the control in the template. <%@ Page Inherits="System.Web.UI.MobileControls.MobilePage" %> <script runat=server language=cs> public void Page_Load() { ArrayList arr = new ArrayList(); arr.Add("a"); arr.Add("a"); arr.Add("a"); arr.Add("a"); list1.DataSource = arr; list1.DataBind(); } public void fn(object s, ListDataBindEventArgs e) { } private bool Evaluate(object c) { MobileListItem mli = (MobileListItem)c; Response.Write (mli.Index); return mli.Index == 2; } </script> <mobile:form runat=server> <mobile:list runat=server id=list1 onitemdatabind=fn> <devicespecific> <choice> <itemtemplate> <asp:label runat=server font-bold="<%# Evaluate(Container) %>" text="<%# ((MobileListItem)Container).Text %>"/>
    </itemtemplate> </choice> </devicespecific> </mobile:list> </mobile:form>
    Hope this helps ... (Simon and Scott)
    Tuesday, August 5, 2003 1:19 PM
  • User-816311723 posted
    I may be a day late and  a dollar short on helping you out with this one, but I am in the middle of roughly the same type of thing.  Something like this ought to work:

    public void lstEmail_OnItemDataBind(object sender, ListDataBindEventArgs e)

    e.Item.Cells[2].Font.Bold = true;


    The 2 is the column you want to make bold.
    Friday, August 19, 2005 2:37 AM